Convert an electronic invoice into an html file
Welcome to Simone Giustetti's wiki pages.
Languages: English - Italiano
How-to Convert a Digital Invoice into a HTML File for Easy Reading
A few years ago the Italian Parliament introduced digital invoices and prompted tax payers, organizations, artisans and self-employed professionals all, to use the new digital format for all of their transactions and invoicing. Full freedom was granted to all of the involved parties to adopt what was needed to comply with the new law. The format adopted to exchange files, consisting in a bunch of XML records, is somewhat uncomfortable for the average human being and is therefore advisable to use software tools to fill out new invoices and to open the received ones.
The Agenzia delle Entrate provides a free (As in free beer) software to fill out tax forms for PCs, which, with a little work, can run on Linux. No suck luck for opening invoices delivered to your PEC (certified e-mail) inbox or downloaded from the SDI (Italian Invoice Exchange Service) web portal; only a few third party applications are freely (As in free beer) available:
I have some issues with those tools:
- No source code available; only binaries. There is no way to debug errors or to customize the software to your work habits;
- No support is provided while installing or using the software;
- I cannot make them work for Slackware Linux.
The latter program is provided in binary exe format for the Windows platform only. Surfing the web I found many Linux users attesting the application works fine with WINE. I tried and was in fact able to install and run it, but when dragging and dropping a new document in the proper area of the main window the program hangs using the CPU heavily to never output anything.
The former software in the list is provided for MicroSoft, Apple and even Linux. Thank you to the developers for taking into account less known desktop platforms. However I was once again unable to run the package. The Java written application requires version 8 of the Java virtual machine from Oracle. As the majority of Linux users worldwide I switched to other providers years ago for the JVM for my Linux boxes to stay as far away as possible from Oracle licensing. I made an exception and installed a virtual machine equipped with JVM 8 from Oracle specifically, but I was unable to go beyond the installation and opening screen of the program.
All in all, considering the amount of invoices I receive from suppliers, It annoys me a lot to have to install, learn to use and periodically update a program which only aim is to format and show a few documents every year. I never considered the many on-line conversion services as a viable solution because of the smell of spam. I may be biased, but all the assured confidentiality crashes against my skepticism and the hundred or so of unwanted e-mails daily cluttering my inbox.
I need a solution to easily read a few digital invoices every year and do not want to spend too much time to install / learn / mange a software for such a trivial task. I spent some time searching for a solution and, after some web surfing and reading the XML file format guides I could find, I came to the conclusion that It can be done without any software. The only thing you really need is a style sheet used for formatting files sent by the exchange service in a readable way. A conversion can be achieved with only the CLI and some common Linux commands. Luckily AssoSoftware provides its style sheet for external use separately from its software. Once you download the style sheet including archive, converting any invoice is a trivial task every user can perform in no time thanks to the versatile and everlasting command line.
Converting a XML File
A style sheet is a file written in XSLT (eXtensible Stylesheet Language Transformations): a programming language meant to transform a XML (eXtensible Markup Language) file into another format, a HTML web page that can be opened by a common web browser for example. The file includes some templates that are applied to XML elements to format them accordingly to the corresponding rules. A style sheet can be combined to a document recurring to the xsltproc command which is part of the libxslt libary included in Slackware and the great majority of Linux distros.
The following command is usable by any user, both administrators and common ones:
xsltproc <path of the style sheet>/<file>.xslt <path of the digital invoice>/<file_1>.xml -o ./<file_2>.html Where: <file> is the name of the style sheet file with formatting / transformation rules. <file_1> is the name of the digital invoice file. -o directs output to a file. Omit it and a sequence of HTML tags will clutter your screen. <file_2> is the name of the converted web page file.
For ease of use you could use the same string for <file_1> and <file_2>, but please be careful not to overwrite your origin file accidentally.
Assuming to use the style sheet downloaded from AssoSoftware and to place both it and the invoice in directory /tmp, the resulting transformation commands will be:
cd /tmp xsltproc ./FoglioStileAssoSoftware.xsl ./IT0XXXXXX07022023j_02Jd8.xml -o ./IT0XXXXXX07022023j_02Jd8.html
The resulting IT0XXXXXX07022023j_02Jd8.html file is a web page in pure HTML, no CSS nor JavaScript, and as such you can open it with a light, fast and secure web browser such as Dillo:
You could transform the invoice recurring to a different style sheet. Whoever is fluent in XML can write its own with custom formatting rules. I'm lazy and I used what was available on-line, but nothing forces you to emulate me.
Converting a P7M Signed File
The invoice file could be digitally signed as attested by the p7m file extension and the encrypted content making it unreadable and preventing it to be successfully transformed. We can again use the command line interface, the tools available in Linux and some brainpower to convert the file. The procedure will consist in two consecutive steps:
- Extract the XML formatted digital invoice from the signed archive;
- Transform the XML file in a HTML web page.
Extract the Digital Invoice
Encrypted files can be managed in Linux with the many tools included in the openssl package. The extraction command will look something like:
openssl smime -verify -noverify -in <path of the signed archive>/<file_1>.xml.p7m -inform DER -out <path of the digital invoice>/<file_2>.xml Where: <file_1> is the name of the signed archive which includes the invoice. <file_2> is the name of the digital invoice XML file.
Let's assume to place both archive and invoice in directory /tmp for example the resulting commands will be:
cd /tmp openssl smime -verify -noverify -in ./IT0XXXXXX07022023j_02Jd8.xml.p7m -inform DER -out ./IT0XXXXXX07022023j_02Jd8.xml
Again be careful not to overwrite the origin file.
Convert the Digital Invoice
Once you have the XML file, please follow the instructions of the previous paragraph to convert it in HTML format.
CONCLUSIONS
This article presents two procedures to convert digital documents into HTML pages readable by a human being. Both the plain XML used for digital invoicing and the digitally signed version were discussed. To carry out the conversion you need a style sheet. Everyone can write its set of rules, but a file is readily available on the net, provided free of charge by the good souls of Assosoftware. The transformation procedures do not require installing software or specific libraries, but use Linux commands only.
For any feedback, questions, errors and such, please e-mail me at studiosg [at] giustetti [dot] net
External links
- AssoInvoice: A free (As in free beer) software to open digital invoices
- A free (As in free beer) style sheet provided by Assoftware (10th March 2025)
Languages: English - Italiano