This topic is locked
[SOLVED]

XML in PDF - xRechnung / Zugpferd invoices

6/10/2024 7:16:04 AM
PHPRunner General questions
mbintex author

Hi at all,

in Germany starting with 2025 we are forced to send electronic invoices in xInvoice/Rechnung or Zugpferd format. Both are a PDFd containing special XML data, that makes clear, who sends the invoice, what is the invoice amount and so on.

Looking at the documentation of pdfmake.js, the PDF engine coming with PHPRunner, I don´t see a way to embed XML into the PDF programmatically though.

Am I missing something?

Do I have to change the PDF library for that purpose?

What PDF library would you recommend?

By the way, a library that would allow resetting the page numbering inside the PDF would be highly appreciated.

M
MikeT 6/10/2024

I would try locally if it's possible to combine the two (pdf created in phpr + xml file) with gs, see here: https://ghostscript.com/blog/zugferd.html
If it works, then look for a hoster that let's you use gs.

HJB 6/10/2024

https://wiki.print2forms.de/doku.php?id=print2forms:tips:tip69c

Sorry, but I made Google to be my best friend :) Or say,
just entered the matchwords "Zugpferd PHP" and BINGO.

mbintex author 6/10/2024

@HJB

well, this requires

a) a third party software
b) a Windows server (which we don´t use)
c) a payed licence based on the number of documents - that can get expensive ... https://www.print2forms.de/informationen.php

Then I´ll be better off with a completely different PDF engine instead of pdfmake.js that can incorporate XML by itself.

This is found by Google too:

https://github.com/easybill/zugferd-php

but it only generates the XML - hard enough, but does not integrate it into a PDF.

@Mike

Personally I would really prefer to generate XML and PDF in one "go", instead of having three steps, that depend on each other.

C
Chris Whitehead 6/10/2024

I found this one which can create a pdf with an XML attachment, it uses the FPDF lib.
https://github.com/horstoeko/zugferd

If you want a basic invoice printer class in php, try this, it's using the FPDF lib as well, maybe you could use it for the invoice layout and the other to add the XML attachment.
https://github.com/artkonekt/pdf-invoice

I'm just wondering if this format will spread from Germany to the UK? Maybe I should be prepared lol.

M
MikeT 6/10/2024

@mbintex Yeah, I understand. I'm not familiar with the Zugferd complexity/requirements. But it seems to be complex enough that if a reliable gs workflow is available it might be even more "dependency free", since you only have to call it from php (and gs is very perfomant).

But that's just me, I like to split things up like that (Unix background, lol).

HJB 6/11/2024

@mbintex

Beginning of 2025 still takes a while and with "business by law", here to make companies of all kinds
compatible, I respect your concerns in regard to higher cost involved, yet on the other hand, question
remains whether we as developers should always try to a kind of provide "free beer for all commercials"
communism. Sure, tampering with laws can become crucial and so, once a third party tool like that would
be bought, though at higher cost, one should be aware off that the third party is then in charge of some
responsibility to keep their tool compliant. Finally, all that time killing issues with "certificates" once "biz by
law" can be a true burden to get cared and held up-to-date. From a YT-video by the Zugpferd solution
providers I understand that their main clientele is among those desktop based form issuers rather than
the cloud busines itself. As a "free trial" is available, I think, we should write to the German developer that
PHPRunners play a significant role in the online industry and so, we would just hoodwink, there are more
customers to serve than the desktop world alone.

mbintex author 6/11/2024

@HJB

I don´t mind paying, since I want to get paid myself :-)

But a solution that requires paying by usage is hard to calculate.

mbintex author 6/11/2024

@Chris

this looks promising to me:

https://github.com/horstoeko/zugferd

Allthough I still would prefer a solution that could write the XML directly to the PDF in one "go".

mbintex author 6/11/2024

Similar to the zugpferd library:

https://github.com/atgp/factur-x

Seems to have less dependencies

K
kohle 6/11/2024

You can send to your customers a xml file (XRechnung) and a separate pdf file instead of a combined ZUGFeRD xml+pdf.

rgs
J.

mbintex author 6/12/2024

@kohle

Technically this seems to be the easiest way.

Waiting for the first customer asking, what this funny xml file should do ...

Of course this way one could stay with pdfmake.js and don´t change anything here.

C
Chris Whitehead 6/12/2024

@mbintex I'd be willing to have a play at this, I'm a little on the busy side at the moment but if you don't find a solution let me know.

mbintex author 6/15/2024

I will go with one of the XRechnung PHP libraries and only hand out a separate XML file.

Never really understood why Xlinesoft got rid of DOMPdf and changed to pdfmake.js. In my eyes DOMPDF did a better job ...