### Complete Maven settings.xml example
Source: https://github.com/zugferd/mustangproject/blob/master/doc/development_documentation.md
An example of a complete Maven settings.xml file including servers and profiles configurations for deployment.
```xml
ossrh
SONATYPE TOKEN USER
SONATYPE TOKEN PASSWORD
ossrh
true
PASSPHRASE
```
--------------------------------
### Command Line Usage Examples
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Examples of how to use the Mustang CLI for various actions like combining XML with PDF, extracting XML, and validating files.
```bash
java -jar Mustang-CLI-2.14.0.jar --action=combine
```
```bash
java -jar Mustang-CLI-2.14.0.jar --action=extract
```
```bash
java -jar Mustang-CLI-2.14.0.jar --action=validate
```
```bash
java -jar Mustang-CLI-2.14.0.jar --help
```
--------------------------------
### Build Project
Source: https://github.com/zugferd/mustangproject/blob/master/README.md
Builds the project, runs tests, and installs artifacts to the local cache.
```shell
mvn clean install
```
--------------------------------
### Install local Maven artifact
Source: https://github.com/zugferd/mustangproject/blob/master/doc/development_documentation.md
Maven command to install a generated JAR file into the local Maven cache, useful for testing functionality before a new release.
```bash
cd validator/target
mvn install:install-file -Dfile="validator-2.17.0-SNAPSHOT-shaded.jar" -Dclassifier=shaded -DgroupId="org.mustangproject" -DartifactId=validator -Dversion="2.17.0" -Dpackaging=jar -DgeneratePom=true
```
--------------------------------
### Valid File Example
Source: https://github.com/zugferd/mustangproject/blob/master/validator/README.md
An example of a valid XML file that conforms to the validation profile.
```xml
-
/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
```
--------------------------------
### Complete Write Example
Source: https://github.com/zugferd/mustangproject/blob/master/doc/ZugferdDev.en.adoc
This Java code demonstrates how to create and export a ZUGFeRD invoice, including setting sender, recipient, items, and bank details, and then exporting it to a PDF file.
```java
package de.usegroup;
import org.mustangproject.*;
import org.mustangproject.ZUGFeRD.IZUGFeRDExporter;
import org.mustangproject.ZUGFeRD.TransactionCalculator;
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromPDFA;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
public class Main {
public static void main(String[] args) {
String sourcePDF="MustangGnuaccountingBeispielRE-20201121_508.pdf";
try {
IZUGFeRDExporter ze = new ZUGFeRDExporterFromPDFA().load(sourcePDF).setProducer("My Application").
setCreator(System.getProperty("user.name"));
Invoice i=new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSender(new TradeParty("ACME co", "teststr", "55232", "teststadt", "DE")
.addBankDetails(new BankDetails("777666555", "DE4321"))).setOwnTaxID("4711").setOwnVATID("DE19990815")
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")
.setContact(new Contact("nameRep", "phoneRep", "emailRep@test.com"))).setNumber("X12")
.addItem(new Item(new Product("Testproduct", "", "H87", new BigDecimal(19)),
new BigDecimal(2.5), new BigDecimal(1.0)));
ze.setTransaction(i);
ze.export("factur-x.pdf");
TransactionCalculator tc=new TransactionCalculator(i);
System.out.println("Confirm "+tc.getDuePayable()+ " is also the final amount in your PDF");
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
--------------------------------
### Embedding ZF2 visualization
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Example of visualizing ZUGFeRD V2 invoices using ZUGFeRDVisualizer.
```java
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
xml = zvi.visualize(sourceName);
Files.write(Paths.get("factur-x.xml"), xml.getBytes());
```
--------------------------------
### Creating and Exporting an Invoice with Mustang
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Java code example demonstrating how to create an Invoice object, set its details, and export it as a ZUGFeRD file using Mustang library.
```Java
import org.mustangproject.Contact;
import org.mustangproject.Invoice;
import org.mustangproject.Item;
import org.mustangproject.Product;
import org.mustangproject.ZUGFeRD.IZUGFeRDExporter;
import org.mustangproject.ZUGFeRD.Profiles;
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1;
import java.math.BigDecimal;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName("My company").setOwnStreet("teststr").setOwnZIP("12345").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new Contact("Franz Müller", "0177123456", "fmueller@test.com", "teststr.12", "55232", "Entenhausen", "DE")).setNumber("INV/123").addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), new BigDecimal(1.0), new BigDecimal(1.0)));
try {
IZUGFeRDExporter ie = new ZUGFeRDExporterFromA1().load("source.pdf").setZUGFeRDVersion(2).setProfile(Profiles.EN16931);
ie.setProfile(Profiles.EN16931).setTransaction(i).export("target.pdf");
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
--------------------------------
### Executing the validator
Source: https://github.com/zugferd/mustangproject/blob/master/validator/README.md
Example of how to execute the Mustangproject validator from the command line, redirecting stderr and escaping file names.
```bash
exec('java -Dfile.encoding=UTF-8 -jar /path/to/ZUV-0.9.0.jar --action validate -f '.escapeshellarg($uploadfile).' 2>/dev/null', $output);
```
--------------------------------
### Invalid File Example
Source: https://github.com/zugferd/mustangproject/blob/master/validator/README.md
An example of an invalid XML file with errors in the XML part.
```xml
-
/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
```
--------------------------------
### Build Mustang Project
Source: https://github.com/zugferd/mustangproject/blob/master/doc/development_documentation.md
Command to build the Mustang project using Maven wrapper.
```bash
mvn clean package
```
--------------------------------
### Responsive Styling for 450px and smaller screens
Source: https://github.com/zugferd/mustangproject/blob/master/library/src/test/resources/factur-x-vis-extended.de.html
CSS rules for adapting to very small screens.
```css
/* 450px und kleiner */
@media screen and (max-width : 450px) {
html, body { font-size: 12px; }
.menue { margin-bottom: 20px; }
button { padding-top: 5px; }
.btnAktiv, .btnInaktiv, .tab { font-size: 17px; height: 35px; }
.btnAktiv:after { top: 35px; }
.legende { display: block; float: left; width: 100%; }
.wert { display: block; float: left; width: 100%; margin-bottom: 10px }
.boxzeile { margin-bottom: 0px }
.boxdaten { height: auto; }
.haftungausschluss { margin-bottom: 20px; }
.boxinhalt { margin-top: 0px; }
.boxabstandtop { margin-top: 20px; }
.boxtitel { padding: 7px 8px; }
.box { margin-bottom: 10px; padding: 0; }
.boxabstandtop { margin-top: 10px; }
.boxdaten, .boxdatenBlock { padding: 2px 0; }
.rechnungSp1 { width: 50%; font-size: inherit; }
.rechnungSp2 { width: 15%; }
.rechnungSp3 { width: 35%; font-size: inherit; text-align: right; }
.grund { font-size: inherit; }
.titelPosition { font-size: 15px; }
.abstandUnten { margin-bottom: 5px; }
.detailsSpalte1, .detailsSpalte2, .detailsSpalte3 { font-size: inherit; line-height: inherit; }
}
```
--------------------------------
### Formatting Styles
Source: https://github.com/zugferd/mustangproject/blob/master/library/src/test/resources/factur-x-vis.fr.html
General formatting rules for colors, weights, spacing, and alignment.
```css
/* Formatierungen */
.color2 {
color: rgba(0, 0, 0, 0.6);
}
.schwarz {
color: #555 !important;
}
.normal {
font-weight: normal;
}
.bold {
font-weight: bold;
}
.abstandUnten {
margin-bottom: 5px;
}
.abstandUntenKlein {
margin-bottom: 10px;
}
.noPaddingTop {
padding-top: 0 !important;
}
.ausrichtungRechts {
text-align: right;
}
```
--------------------------------
### ZUGFeRDImporter Usage
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Example of using the ZUGFeRDImporter to extract invoice data.
```Java
ZUGFeRDImporter zi = new ZUGFeRDImporter(inputStream);
String amount = zi.getAmount();
```
--------------------------------
### Using nodeMap.getAsString and nodeMap.getAsNodeMap
Source: https://github.com/zugferd/mustangproject/blob/master/doc/development_documentation.md
Demonstrates using nodeMap to extract string values for seller/buyer IDs, name, and description, and processing nested node maps for product characteristics and classifications.
```java
nodeMap.getAsString("SellerAssignedID").ifPresent(this::setSellerAssignedID);
nodeMap.getAsString("BuyerAssignedID").ifPresent(this::setBuyerAssignedID);
nodeMap.getAsString("Name").ifPresent(this::setName);
nodeMap.getAsString("Description").ifPresent(this::setDescription);
nodeMap.getAsNodeMap("ApplicableProductCharacteristic").ifPresent(apcNodes -> {
String key = apcNodes.getAsStringOrNull("Description");
String value = apcNodes.getAsStringOrNull("Value");
if (key != null && value != null) {
if (attributes == null) {
attributes = new HashMap<>();
}
attributes.put(key, value);
}
});
nodeMap.getAsNodeMap("DesignatedProductClassification").ifPresent(dpcNodes -> {
String className = dpcNodes.getAsStringOrNull("ClassName");
dpcNodes.getNode("ClassCode").map(ClassCode::fromNode).ifPresent(classCode ->
classifications.add(new DesignatedProductClassification(classCode, className)));
});
nodeMap.getAsString("OriginTradeCounty").ifPresent(this::setCountryOfOrigin);
```
--------------------------------
### Responsive Styling for 800px and smaller screens
Source: https://github.com/zugferd/mustangproject/blob/master/library/src/test/resources/factur-x-vis-extended.de.html
CSS rules for further adaptation to smaller screens.
```css
/* 800px und kleiner */
@media screen and (max-width : 800px) {
button { padding-top: 10px; }
.btnAktiv, .btnInaktiv, .tab { font-size: 20px; height: 40px; }
.btnAktiv:after { top: 40px; }
.rechnungSp1 { width: 55%; font-size: 15px; }
.rechnungSp2 { width: 10%; }
.rechnungSp3 { width: 35%; text-align: right; font-size: 15px; }
.grund { font-size: 15px; }
}
```
--------------------------------
### Embedding the validator - Java Usage
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Example of using the ZUGFeRDValidator to validate an XML file.
```java
import org.mustangproject.validator.ZUGFeRDValidator;
public class Main {
public static void main(String[] args) {
ZUGFeRDValidator zfv = new ZUGFeRDValidator();
System.out.println(zfv.validate("/tmp/factur-x.xml"));
}
}
```
--------------------------------
### ZUGFeRDExporter Update
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Example showing the change in how ZUGFeRDExporter is instantiated and configured from Mustang 1.x to 2.0.
```Java
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.COMFORT).load(SOURCE_PDF)) {
```
```Java
IZUGFeRDExporter ze = new ZUGFeRDExporterFromA1().setZUGFeRDVersion(1).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931).load(SOURCE_PDF)) {
```
--------------------------------
### Responsive Styling for 1023px and smaller screens
Source: https://github.com/zugferd/mustangproject/blob/master/library/src/test/resources/factur-x-vis-extended.de.html
CSS rules to adapt the layout for medium-sized screens.
```css
/* 1023px und kleiner */
@media screen and (max-width : 1023px) {
.box { display: block; width: 100%; margin-bottom: 20px; }
.boxabstandtop { margin-top: 15px; }
.subBox:first-child { margin-bottom: 0 !important; }
.subBox:last-child { border-left: 1px solid rgba(4, 101, 161, 0.2); }
.first > .boxzeile > .subBox { border-top: none !important; }
.first > .boxzeile > .subBox:first-child { border-top: 1px solid rgba(4, 101, 161, 0.2) !important; }
.first > .boxzeile { margin-bottom: 0; }
#uebersichtUeberweisung.box { border-left: 1px solid rgba(4, 101, 161, 0.2); }
#uebersichtLastschrift.box { margin-bottom: 0; }
.boxzeile { display: block; margin-bottom: 5px; }
.boxzeile:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
#details > .boxtabelle > .boxzeile { margin-bottom: 0px; }
.boxcell { display: block; }
.boxcell:last-child { margin-top: 20px; }
.boxZweispaltig { width: 100%; }
.legende { display: block; float: left; width: 170px; padding: 5px 0; height: auto; }
.wert { display: block; float: left; width: calc(100% - 170px); padding: 11px 10px !important; line-height: 1.3; min-height: 38px; height: auto; }
.boxdaten .legende { height: auto; }
.rechnungsZeile .boxdaten { padding: 5px 0; }
.boxabstand { display: none; }
.boxtabelleEinspaltig { width: 100%; }
.boxSpalte1 { display: block; width: auto; }
.boxSpalte2 { display: block; width: auto; padding-left: 0px; margin-top: 1.2rem; }
.detailsSpalte1, .detailsSpalte2, .detailsSpalte3 { width: 100%; float: none; padding-right: 0px; }
.detailsSpalte2, .detailsSpalte3 { margin-top: 15px; }
.detailsSpalte2, .detailsSpalte3 { margin-top: 10px; }
.tableNumberAlignRight { display: block; width: 130px; text-align: right; }
}
```
--------------------------------
### Export XML
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Example of creating an Invoice object and generating its XML representation using ZUGFeRD2PullProvider.
```java
Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new Contact("Franz Müller", "0177123456", "fmueller@test.com", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)));
```
```java
ZUGFeRD2PullProvider zf2p = new ZUGFeRD2PullProvider();
zf2p.generateXML(i);
String theXML = new String(zf2p.getXML(), StandardCharsets.UTF_8);
```
--------------------------------
### Responsive Styling for 380px and smaller screens
Source: https://github.com/zugferd/mustangproject/blob/master/library/src/test/resources/factur-x-vis-extended.de.html
CSS rules for adapting to very small screens, with further font size adjustments.
```css
/* 380px und kleiner */
@media screen and (max-width : 380px) {
html, body { font-size: 11px; line-height: 100%; }
.btnAktiv, .btnInaktiv, .tab { font-size: 15px; }
.boxdaten .boxdatenBlock { padding: 2px 0; }
.boxinhalt { margin-top: 0px; }
.boxtitel { padding: 5px 7px; }
}
```
--------------------------------
### Maven settings.xml servers configuration
Source: https://github.com/zugferd/mustangproject/blob/master/doc/development_documentation.md
Configuration snippet for the 'servers' section in Maven's settings.xml to include credentials for GitHub and OSSRH.
```xml
github
GITHUB-TOKEN
ossrh
jstaerk
JIRA-PASSWORD
```
--------------------------------
### Maven release commands
Source: https://github.com/zugferd/mustangproject/blob/master/doc/development_documentation.md
Sequence of Maven commands to clean, prepare, and perform a release.
```bash
mvn clean install
* `mvn javadoc:javadoc`. If that works you can
* clean the release with `mvn release:clean` and prepare the release with
* `mvn release:prepare` and enter the version numbers.
* After that is through you can create a new release via `mvn release:perform`.This will also update the maven repo.
```
--------------------------------
### Embedding ZF1 to ZF2 migration
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Example of migrating XML from ZUGFeRD V1 to V2 using the XMLUpgrader.
```java
XMLUpgrader zmi = new XMLUpgrader();
String xml = zmi.migrateFromV1ToV2(xmlName);
Files.write(Paths.get(outName), xml.getBytes());
```
--------------------------------
### New ZUGFeRDInvoiceImporter Usage
Source: https://github.com/zugferd/mustangproject/blob/master/Release_Notes.md
Example demonstrating the usage of the new ZUGFeRDInvoiceImporter to extract invoice details and perform assertions.
```Java
ZUGFeRDInvoiceImporter zii=new ZUGFeRDInvoiceImporter(TARGET_PDF);
Invoice invoice=null;
try {
invoice=zii.extractInvoice();
} catch (XPathExpressionException | ParseException e) {
// handle Exceptions
}
assertFalse(hasExceptions);
// Reading ZUGFeRD
assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName());
assertEquals(3, invoice.getZFItems().length);
assertEquals("400.0000", invoice.getZFItems()[1].getQuantity().toString());
assertEquals("160.0000", invoice.getZFItems()[0].getPrice().toString());
assertEquals("Heiße Luft pro Liter", invoice.getZFItems()[2].getProduct().getName());
assertEquals("LTR", invoice.getZFItems()[2].getProduct().getUnit());
assertEquals("7.00", invoice.getZFItems()[0].getProduct().getVATPercent().toString());
assertEquals("RE-20170509/505", invoice.getNumber());
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
assertEquals("2017-05-09",sdf.format(invoice.getIssueDate()));
assertEquals("Bahnstr. 42", invoice.getRecipient().getStreet());
assertEquals("88802", invoice.getRecipient().getZIP());
assertEquals("DE", invoice.getRecipient().getCountry());
assertEquals("Spielkreis", invoice.getRecipient().getLocation());
TransactionCalculator tc=new TransactionCalculator(invoice);
assertEquals(new BigDecimal("571.04"),tc.getTotalGross());
```
--------------------------------
### NodeList from an XPath
Source: https://github.com/zugferd/mustangproject/blob/master/doc/development_documentation.md
Example of compiling an XPath expression to retrieve a NodeList of elements with a local name 'PrepaidAmount' and extracting attributes from a 'GlobalID' node.
```java
xpr = xpath.compile("//*[local-name()=\"PrepaidAmount\"]");
NodeList prepaidNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
nodeMap.getNode("GlobalID").ifPresent(idNode -> {
if (idNode.hasAttributes()
&& idNode.getAttributes().getNamedItem("schemeID") != null) {
globalId = new SchemedID()
.setScheme(idNode.getAttributes().getNamedItem("schemeID").getNodeValue())
.setId(idNode.getTextContent());
}
});
```
--------------------------------
### Complete Sample Source Code for Reading ZUGFeRD Data
Source: https://github.com/zugferd/mustangproject/blob/master/doc/ZugferdDev.en.adoc
A complete Java class demonstrating how to read ZUGFeRD data from a PDF.
```java
package de.usegroup;
import org.mustangproject.CalculatedInvoice;
import org.mustangproject.ZUGFeRD.ZUGFeRDInvoiceImporter;
import javax.xml.xpath.XPathExpressionException;
import java.text.ParseException;
public class Main {
public static void main(String[] args) {
ZUGFeRDInvoiceImporter zii=new ZUGFeRDInvoiceImporter("MustangGnuaccountingBeispielRE-20201121_508.pdf");
CalculatedInvoice ci=new CalculatedInvoice();
try {
zii.extractInto(ci);
System.out.println("Pay: "+ci.getDuePayable());
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}
```