atgp/factur-x

Generated file name

thierryler opened this issue · 4 comments

Is it possible to add code to specify the wanted name (next to outputFilePath) for the generated file?

Now, I have to copy the file to change the name:

$pdfInvoiceFile = '/var/pdf/f4/invoice-' . $invoice->id . '.pdf';
$pdfInvoicexFile = '/var/pdf/f4/invoicex-' . $invoice->id . '.pdf';
$facturx = new Facturx();
$generatedFacturxFile = $facturx->generateFacturxFromFiles(
  $pdfInvoiceFile,
  $xmlInvoiceFile,
  'autodetect', // facturxProfil
  false, // checkXsd
  '/var/pdf/f4/xml', // outputFilePath
  [], // additionalAttachments
  true, // addFacturxLogo
  'Data' // relationship
);
// rename($generatedFacturxFile, $pdfInvoicexFile);
copy($generatedFacturxFile, $pdfInvoicexFile);

Hi @thierryler,

Indeed, could you make a pull request about it to allow to use outputFilePath to be a directory or a file ?

I do not have the skills to create a pull request on php.

In the code, I think we can simply add $outputFileName = '' in the function parameters.

And replace

$facturxGeneratedFileName = 'invoice-facturx-'.date('Ymdhis').'.pdf';

by

$facturxGeneratedFileName = $outputFileName;
if(empty($facturxGeneratedFileName)) {
    $facturxGeneratedFileName = 'invoice-facturx-'.date('Ymdhis').'.pdf';
}

I would like to split the method generateFacturxFromFiles into 2 new ones :

  • generate() that generates a string
  • save() that saves the generated pdf into a string

I can also remove the option to export on a file, because it's easy to use a file_put_content or a a resource.

Closed with #28 : I remove the method to save into file.
You can use your own code to save to a file.

$writer = new \Atgp\FacturX\Writer();
$facturxPdf = $writer->generate($pdf, $facturxXml);

file_put_content('my-facturx.pdf', $facturxPdf);