Create a generic PDF file from a CFDI 3.3
In some cases you just simply need a PDF file from a Mexican CFDI (Comprobante Fiscal Digital por Internet). This tool help you to create a generic one. You can also use it to build your own and pretty formats.
Use composer, so please run
composer require phpcfdi/cfditopdf
$ bin/cfditopdf --help
bin/cfditopdf [options] <cfdi-file> [<pdf-file>]
-h, --help Show this help
-v, --version Show command version
-d, --dirty Do not try to clean up the cfdi file
-l, --resource-location Use this path to store the xml resources locally,
if none then it will always download xlst resources
cfdi-file Path of the XML file (input file)
pdf-file Path of the PDF file (output file) if none then it will remove
".xml" extension and sufix ".pdf" extension
<?php declare(strict_types=1);
$cfdifile = 'datafiles/cfdi.xml';
$xml = file_get_contents($cfdifile);
// clean cfdi
$xml = \CfdiUtils\Cleaner\Cleaner::staticClean($xml);
// create the main node structure
$comprobante = \CfdiUtils\Nodes\XmlNodeUtils::nodeFromXmlString($xml);
// create the CfdiData object, it contains all the required information
$cfdiData = (new \PhpCfdi\CfdiToPdf\CfdiDataBuilder())
->build($comprobante);
// create the converter
$converter = new \PhpCfdi\CfdiToPdf\Converter(
new \PhpCfdi\CfdiToPdf\Builders\Html2PdfBuilder()
);
// create the invoice as output.pdf
$converter->createPdfAs($cfdiData, 'output.pdf');
This library is compatible with PHP versions 7.0 and above. Please, try to use the full potential of the language.
Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look in the TODO and CHANGELOG files.
The phpcfdi/cfditopdf library is copyright © Carlos C Soto and licensed for use under the MIT License (MIT). Please see LICENSE for more information.