# ZUV ZUV (ZUgferd+[VeraPDF](http://VeraPDF.org)) is an open-source e-invoice validator for the [ZUGFeRD](https://www.ferd-net.de/zugferd/specification/index.html)/[Factur-X](http://fnfe-mpe.org/factur-x/) standard. It checks both PDF/A-3 compliance (based on VeraPDF) and ZUGFeRD version 1 respectively 2/2.1 XMLs for correctness. The XML check is done by validating against the official ZUGFeRD schematron file for v1 and v2.1 and additionally the EN16931 UN/CEFACT SCRDM v16B uncoupled schematron from the [CEN](https://github.com/CenPC434/validation). ## Build In the pom.xml directory compile the jar with `./mvnw clean package` To prepare the schematron files they have to be converted to XSLT files, which is done with a XSLT transformation itself. Get [Saxon](http://saxon.sourceforge.net/#F9.9HE) and the [XSLT](https://github.com/Schematron/stf/tree/master/iso-schematron-xslt2) to convert schematron to XSLT and run `java -jar ./saxon9he.jar -o:minimum.xsl -s:zugferd2p0_basicwl_minimum.sch ./schematron_to_xslt/iso-schematron-xslt2/iso_svrl_for_xslt1.xsl` to do so. To create a new en16931 run ` git clone https://github.com/ConnectingEurope/eInvoicing-EN16931.git mvn -f pom-xslt.xml package ` ## Run To check a file for ZUGFeRD conformance use `java -jar ZUV-0.9.0.jar --action validate -f ` You can provide either the complete PDF which will be checked for XML and PDF correctness, or just a XML file, which of course will only be checked for XML correctness. ## Output A valid file looks like this ``` /Users/jstaerk/workspace/zugferd/helper_files/../foreign_samples/fx/Facture_UE_MINIMUM.pdf
00:00:01.419 1 0 0 00:00:01.682 Factur/X Python 2361 2 urn:factur-x.eu:1p0:minimum 26 0 2772 ``` Invalid files with errors e.g. in the XML part can look like this ``` /Users/jstaerk/workspace/zugferd/helper_files/../foreign_samples/fx/Facture_UE_EXTENDED.pdf
00:00:01.342 1 0 0 00:00:01.602 Factur/X Python 2296 2 urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended 97 1 8546 In an Invoice with a VAT breakdown (BG-23) where the VAT category code (BT-118) is "Intra-community supply" the Actual delivery date (BT-72) or the Invoicing period (BG-14) shall not be blank. ``` ## Embed Feel free to embed this into your java software, send me a PR to use it as a library, or exec it and parse it's output to put on the web. For exec, you might try something like ``` exec('java -Dfile.encoding=UTF-8 -jar /path/to/ZUV-0.9.0.jar --action validate -f '.escapeshellarg($uploadfile).' 2>/dev/null', $output); ``` * Redirecting stderr away (some logging messages might otherwise disturb XML well formedness) * Escaping any file names in case you use original file names at all (apart from security concerns please take into account that they might contain spaces) * Signal java to use UTF-8 even when otherwise it would not: You might run into trouble with XML files starting with a BOM otherwise and when you exec, keep in mind that you lose all env vars. ## License Permissive Open Source APL2, see LICENSE ## Codes | section | meaning | |---|---| | 1 | file not found | | 2 | additional data schema validation fails | | 3 | xml data not found | | 4 | schematron rule failed | | 5 | file too small | | 6 | VeraPDFException | | 7 | IOException PDF | | 8 | File does not look like PDF nor XML (contains neither %PDF nor