ZUGFeRD/XRechnung/Factur-X made easy
From January 1, 2025, electronic invoicing (“e-billing”) will become the mandatory standard for billing between companies, with various exceptions and transition periods. The computer magazine c't took up the topic in its 26/2024 issue and wrote several articles. Here is a link to sources and downloads.
The accounting programs of large companies certainly include support for electronic invoices to a large extent. However, smaller companies that have previously created their invoices in Word, Excel or similar programs are left out in the cold and have to look for other, often fee-based solutions.
Mit dem kostenlosen ZUGFeRD-Composer sind diese Zeiten vorbei. Das Archiv enthält zahlreiche Beispiele für die Erstellung von rechtsgültiger ZUGFeRD– (das sind PDF-Dateien mit eingebetteten XML-Daten – das identische Format heißt in Frankreich Factur-X) oder XRechnung-Dateien (reines XML-Format). Hier finden Sie mehr Details darüber.
The composer uses the free ZUGFeRD library by Stephan Stapel, who has put a lot of work into the library and rightly asks for support . Libraries are available for other programming languages than C#, e.g. for php.
The idea behind it
The example of automatically sending e-mails using hidden text inspired us to come up with a similar solution.
Predefined templates are simply inserted in small white letters at the appropriate places in the invoice documents and filtered out of the page text by the composer.
The composer contains a configuration file with defined keys (e.g. invoice_nr
) and instructions for extracting the data. This could look something like this:
/// Force a number format from a country e.g. DE-DE
number_format: 1:c:[NF]:⁞
//# ----------- Invoice -----------------
// BT-1
invoice_nr: 0:c:[01]:⁞
// BT-2
invoice_date: 0:c:[02]:⁞
// BT-3: Invoice = 380, Unknown = 0: Use string or number
invoice_type: 0:c:[03]:⁞
// BT-5: EUR, USD, ...
invoice_currency: 0:c:[05]:⁞
// BT-9:
invoice_payment_due_date: 0:c:[09]:⁞
// BT-9:
invoice_payment_description: 1:c:[20]:⁞
The colon is used as the separator; '0/1'
for mandatory/optional; 'c'
for character; '[01]'
is, for example, the start text; '⁞'
is a rare character from the Unicode character set to mark the end of the text. In this case, the text in between is used as the invoice number. You can configure all of this, including the separator, as needed.
If you take a look at the above invoice excerpt, you will recognize the invoice number enclosed by the patterns.
Create text representation from the invoice
For the composer to work, the content of the invoice document, regardless of the format, must be provided to the composer as text. There are various ways of doing this.
- The most obvious option is to create the text file programmatically and to use the composer only as a command line for the ZUGFeRD library. Of course, you can also use the library directly.
- You copy the entire invoice content to the clipboard and open the composer with the option
'/iC'
. However, this does not work in many programs. For example, it does not work in Word if you use text boxes or embedded objects. - Composer can extract the text from invoice documents using the IFilter technique. Windows uses this method for the full text search. The download archive also contains the
"IFilterCmd"
tool. Simply call it up with a Word, PDF or other file. It can also handle wildcards ("IFilterCmd /S *.pdf" creates a *.pdf.txt file for all PDF files in the current directory and all subdirectories).
Internally, the option'/w " "'
is used to avoid unwanted hyphens.Composer can extract the text from invoice documents using the IFilter technique. Windows uses this method for the full text search. The download archive also contains the"IFilterCmd"
tool. Simply call it up with a Word, PDF or other file. It can also handle wildcards ("IFilterCmd /S *.pdf" creates a *.pdf.txt file for all PDF files in the current directory and all subdirectories).
Internally, the option'/w " "'
is used to avoid unwanted hyphens. - PrintMulti kann während des Druckens Texte aus dem Druckdatenstrom extrahieren. Dazu sollte die neueste Version 2.0.0.8 verwendet werden, die Verbesserungen in diesem Bereich enthält. Dies funktioniert dann z.B. auch mit eingebetteten Objekten in Word. Viele Softwareprodukte setzen auf Reportgeneratoren oder html-Rechnungen. Wenn Sie dort versteckte Texte einfügen können, funktioniert es wahrscheinlich auch mit PrintMulti.
Sie können PrintMulti auch auf einem Server installieren (dann aber lizenzpflichtig) und den Drucker freigeben, so dass bei mehreren Arbeitsplätzen eine zentrale Ablage der elektronischen Rechnungen erfolgen kann.
Details can be found under the following links: README, manual and description of the examples
To try it out, it's best to download the archive, unzip it to "C:\ZUGFeRDComposer" and then open the "RunExamples.cmd" file in the "Examples/Word" subdirectory "RunExamples.cmd".
You can also simply open one of the Word or LibreOffice documents, copy the entire content to the clipboard and open the batch file "C:\ZUGFeRDComposer\Examples\RunFromClipboard.cmd".
After that, Explorer should open the directory “C:\ZUGFeRDComposer\2025-0002” (2025-002 is the invoice number), which contains several ZUGFeRD and XRechnung files.
The Word files with macros include macros for showing and hiding the special formatting templates "Hidden" and "Hidden optional". Here are links to the complete invoice with visible texts and invisible texts
In the upper left corner, you can see the four macros (green: Hide, red: Show, 😁: IFilter, ⚭: Clipboard).
The composer does not yet support all the possibilities of electronic invoices (see README). Extensions are probably easily possible, provided the library supports it.