PHP code example of phpcfdi / cfditopdf

1. Go to this page and download the library: Download phpcfdi/cfditopdf 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/ */

    

phpcfdi / cfditopdf example snippets


 declare(strict_types=1);

$cfdifile = 'datafiles/cfdi.xml';
$xml = file_get_contents($cfdifile);

// clean cfdi
$xml = \PhpCfdi\CfdiCleaner\Cleaner::staticClean($xml);

// create the main node structure
$comprobante = \CfdiUtils\Nodes\XmlNodeUtils::nodeFromXmlString($xml);

// create the CfdiData object, it contains all the 

 declare(strict_types=1);
$htmlTranslator = new \PhpCfdi\CfdiToPdf\Builders\HtmlTranslators\PlatesHtmlTranslator(
    'directory_where_templates_are_located',
    'main_template_name'
);
$converter = new \PhpCfdi\CfdiToPdf\Converter(
    new \PhpCfdi\CfdiToPdf\Builders\Html2PdfBuilder($htmlTranslator)
);