toecount can now also merge and extract zugferd PDF files+xml structure
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
||||||
<artifactId>toecount</artifactId>
|
<artifactId>toecount</artifactId>
|
||||||
<version>0.0.9-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>ZUGFeRD PDF checker</name>
|
<name>ZUGFeRD PDF checker</name>
|
||||||
<description>Shows statistics on how many PDFs in a directory are ZUGFeRD-Compliant</description>
|
<description>Shows statistics on how many PDFs in a directory are ZUGFeRD-Compliant</description>
|
||||||
<repositories>
|
<repositories>
|
||||||
@@ -23,6 +23,22 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- jaxb?
|
||||||
|
javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory not found
|
||||||
|
-->
|
||||||
|
<!-- >dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.2.5</version>
|
||||||
|
</dependency -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-impl</artifactId>
|
||||||
|
<version>2.2.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
||||||
<artifactId>mustang</artifactId>
|
<artifactId>mustang</artifactId>
|
||||||
|
|||||||
@@ -7,44 +7,50 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
|
||||||
|
import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
|
||||||
|
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
||||||
|
|
||||||
import com.sanityinc.jargs.CmdLineParser;
|
import com.sanityinc.jargs.CmdLineParser;
|
||||||
import com.sanityinc.jargs.CmdLineParser.Option;
|
import com.sanityinc.jargs.CmdLineParser.Option;
|
||||||
|
|
||||||
public class Toecount {
|
public class Toecount {
|
||||||
// build with: /opt/local/bin/mvn clean compile assembly:single
|
// build with: /opt/local/bin/mvn clean compile assembly:single
|
||||||
private static void printUsage() {
|
private static void printUsage() {
|
||||||
System.err
|
System.err.println(getUsage());
|
||||||
.println(getUsage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getUsage() {
|
private static String getUsage() {
|
||||||
return "Usage: Toecount [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] [-h,--help]\r\n";
|
return "Usage: Toecount [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] | [-c,--combine] | [-e,--extract] | [-h,--help]\r\n";
|
||||||
}
|
|
||||||
private static void printHelp() {
|
|
||||||
System.out
|
|
||||||
.println("Mustangproject.org's Toecount 0.0.7 \r\n"
|
|
||||||
+ "A Apache Public License command line tool for statistics on PDF invoices with\r\n"
|
|
||||||
+ "ZUGFeRD Metadata (http://www.zugferd.de)\r\n"
|
|
||||||
+ "\r\n"
|
|
||||||
+ getUsage()
|
|
||||||
+ "\t--directory= can specify a single PDF or a directory to be scanned\r\n"
|
|
||||||
+ "\t\tIf it is a directory, it will recurse.\r\n"
|
|
||||||
+ "\t--listfromstdin allows to specify a list of linefeed separated files on runtime.\r\n"
|
|
||||||
+ "\t\tIt will start once a blank line has been entered.\r\n"
|
|
||||||
+ "\t--ignorefileextension check *.* instead of *.pdf files");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void printHelp() {
|
||||||
|
System.out.println("Mustangproject.org's Toecount 0.1.0 \r\n"
|
||||||
|
+ "A Apache Public License command line tool for statistics on PDF invoices with\r\n"
|
||||||
|
+ "ZUGFeRD Metadata (http://www.zugferd.org)\r\n" + "\r\n" + getUsage() + "Count operations"
|
||||||
|
+ "\t--directory= count ZUGFeRD files in directory to be scanned\r\n"
|
||||||
|
+ "\t\tIf it is a directory, it will recurse.\r\n"
|
||||||
|
+ "\t--listfromstdin=count ZUGFeRD files from a list of linefeed separated files on runtime.\r\n"
|
||||||
|
+ "\t\tIt will start once a blank line has been entered.\r\n"
|
||||||
|
+ "\t--ignorefileextension=if PDF files are counted check *.* instead of *.pdf files"
|
||||||
|
+ "Merge operations"
|
||||||
|
+ "\t--combine= combine ZUGFeRD-invoice.xml and invoice.pdf to invoice.zugferd.pdf\r\n"
|
||||||
|
+ "\t--extract= extract invoice.zugferd.pdf to ZUGFeRD-invoice.xml\r\n"
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// /opt/local/bin/mvn clean compile assembly:single
|
// /opt/local/bin/mvn clean compile assembly:single
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
CmdLineParser parser = new CmdLineParser();
|
CmdLineParser parser = new CmdLineParser();
|
||||||
Option<String> dirnameOption = parser.addStringOption('d', "directory");
|
Option<String> dirnameOption = parser.addStringOption('d', "directory");
|
||||||
Option<Boolean> filesFromStdInOption = parser.addBooleanOption('l',
|
Option<Boolean> filesFromStdInOption = parser.addBooleanOption('l', "listfromstdin");
|
||||||
"listfromstdin");
|
Option<Boolean> ignoreFileExtOption = parser.addBooleanOption('i', "ignorefileextension");
|
||||||
Option<Boolean> ignoreFileExtOption = parser.addBooleanOption('i',
|
Option<Boolean> combineOption = parser.addBooleanOption('c', "combine");
|
||||||
"ignorefileextension");
|
Option<Boolean> extractOption = parser.addBooleanOption('e', "extract");
|
||||||
Option<Boolean> helpOption = parser.addBooleanOption('h',
|
Option<Boolean> helpOption = parser.addBooleanOption('h', "help");
|
||||||
"help");
|
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
printUsage();
|
printUsage();
|
||||||
@@ -61,19 +67,22 @@ public class Toecount {
|
|||||||
|
|
||||||
String directoryName = parser.getOptionValue(dirnameOption);
|
String directoryName = parser.getOptionValue(dirnameOption);
|
||||||
|
|
||||||
Boolean filesFromStdIn = parser.getOptionValue(filesFromStdInOption,
|
Boolean filesFromStdIn = parser.getOptionValue(filesFromStdInOption, Boolean.FALSE);
|
||||||
Boolean.FALSE);
|
|
||||||
|
|
||||||
Boolean helpRequested = parser.getOptionValue(helpOption,
|
Boolean combineRequested = parser.getOptionValue(combineOption, Boolean.FALSE);
|
||||||
Boolean.FALSE);
|
|
||||||
|
|
||||||
Boolean ignoreFileExt = parser.getOptionValue(ignoreFileExtOption,
|
Boolean extractRequested = parser.getOptionValue(extractOption, Boolean.FALSE);
|
||||||
Boolean.FALSE);
|
|
||||||
|
Boolean helpRequested = parser.getOptionValue(helpOption, Boolean.FALSE);
|
||||||
|
|
||||||
|
Boolean ignoreFileExt = parser.getOptionValue(ignoreFileExtOption, Boolean.FALSE);
|
||||||
|
|
||||||
if (helpRequested) {
|
if (helpRequested) {
|
||||||
printHelp();
|
printHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (((directoryName!= null) && (directoryName.length() > 0)) || filesFromStdIn.booleanValue()) {
|
||||||
|
|
||||||
StatRun sr = new StatRun();
|
StatRun sr = new StatRun();
|
||||||
if (ignoreFileExt) {
|
if (ignoreFileExt) {
|
||||||
sr.ignoreFileExtension();
|
sr.ignoreFileExtension();
|
||||||
@@ -119,5 +128,38 @@ public class Toecount {
|
|||||||
|
|
||||||
}
|
}
|
||||||
System.out.println(sr.getSummaryLine());
|
System.out.println(sr.getSummaryLine());
|
||||||
|
} else if (combineRequested) {
|
||||||
|
/*
|
||||||
|
* ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
|
||||||
|
* .setProducer("toecount")
|
||||||
|
* .setCreator(System.getProperty("user.name"))
|
||||||
|
* .loadFromPDFA1("invoice.pdf");
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
ZUGFeRDExporter ze = new ZUGFeRDExporter();
|
||||||
|
ze.PDFmakeA3compliant("./invoice.pdf", "Toecount", System.getProperty("user.name"), true);
|
||||||
|
ze.setZUGFeRDXMLData(Files.readAllBytes(Paths.get("./ZUGFeRD-invoice.xml")));
|
||||||
|
ze.PDFattachZugferdFile(null);
|
||||||
|
ze.export("invoice.ZUGFeRD.pdf");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (TransformerException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Written to invoice.ZUGFeRD.pdf");
|
||||||
|
} else if (extractRequested) {
|
||||||
|
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
||||||
|
zi.extract("invoice.zugferd.pdf");
|
||||||
|
try {
|
||||||
|
Files.write(Paths.get("./ZUGFeRD-invoice.xml"), zi.getRawXML());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
System.out.println("Written to ZUGFeRD-invoice.xml");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user