PHP code example of guilhermecfviana / nfsenacional

1. Go to this page and download the library: Download guilhermecfviana/nfsenacional library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

guilhermecfviana / nfsenacional example snippets




declare(strict_types=1);

\Danfse\DanfseGenerator;

$generator = new DanfseGenerator();

// 1) Gerar DANFSe em memoria
$pdfBinary = $generator->generate(__DIR__ . '/assets/xml/nfse.xml');

// 2) Gerar DANFSe em arquivo
$generator->generate(
		__DIR__ . '/assets/xml/nfse.xml',
		[
				'output' => 'file',
				'outputPath' => __DIR__ . '/saida/danfse.pdf',
		]
);

// 3) Gerar a partir de XML em string
$xml = file_get_contents(__DIR__ . '/assets/xml/nfse.xml');
$pdfBinaryFromString = $generator->generate((string) $xml);

$generator->generate(
		$xmlContent,
		[
				'output' => 'file',
				'outputPath' => __DIR__ . '/saida/danfse.pdf',
				'watermark' => 'substituida', // ou 'cancelada'
		]
);