update command lines for xml to pdf
This commit is contained in:
@@ -102,6 +102,9 @@ public class Main {
|
||||
+ " [--language <lang>]: set output lang (en, fr or de)\n"
|
||||
+ " [--source <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: set output HTML file\n"
|
||||
+ " --action pdf convert XML to PDF \n"
|
||||
+ " [--source <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: set output PDF file\n"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -115,15 +118,11 @@ public class Main {
|
||||
* Asks the user (repeatedly, if neccessary) on the command line for a String
|
||||
* (offering a defaultValue) conforming to a Regex pattern
|
||||
*
|
||||
* @param prompt
|
||||
* the question to be asked to the user
|
||||
* @param defaultValue
|
||||
* the default return value if user hits enter
|
||||
* @param pattern
|
||||
* a regex of acceptable values
|
||||
* @param prompt the question to be asked to the user
|
||||
* @param defaultValue the default return value if user hits enter
|
||||
* @param pattern a regex of acceptable values
|
||||
* @return the user answer conforming to pattern
|
||||
* @throws Exception
|
||||
* if pattern not compielable or IOexception on input
|
||||
* @throws Exception if pattern not compielable or IOexception on input
|
||||
*/
|
||||
protected static String getStringFromUser(String prompt, String defaultValue, String pattern) throws Exception {
|
||||
String input = "";
|
||||
@@ -242,6 +241,7 @@ public class Main {
|
||||
|
||||
return selectedName;
|
||||
}
|
||||
|
||||
private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException {
|
||||
|
||||
// Get params from user if not already defined
|
||||
@@ -330,6 +330,7 @@ public class Main {
|
||||
// return result.toString(StandardCharsets.UTF_8);
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* the main function of the commandline tool...
|
||||
* @param args the commandline args, see also https://www.mustangproject.org/commandline/#verbose
|
||||
@@ -384,8 +385,6 @@ public class Main {
|
||||
String[] attachmentFilenames = cmd.hasOption("attachments") ? cmd.getOptionValues("attachments") : null;
|
||||
|
||||
|
||||
|
||||
|
||||
ArrayList<FileAttachment> attachments = new ArrayList<>();
|
||||
if (helpRequested) {
|
||||
printHelp();
|
||||
@@ -405,8 +404,11 @@ public class Main {
|
||||
} else if ((action != null) && (action.equals("a3only"))) {
|
||||
performConvert(sourceName, outName);
|
||||
optionsRecognized = true;
|
||||
} else if ((action != null) && (action.equals("pdf"))) {
|
||||
performVisualization(sourceName, lang, outName, true);
|
||||
optionsRecognized = true;
|
||||
} else if ((action != null) && (action.equals("visualize"))) {
|
||||
performVisualization(sourceName, lang, outName);
|
||||
performVisualization(sourceName, lang, outName, false);
|
||||
optionsRecognized = true;
|
||||
} else if ((action != null) && (action.equals("upgrade"))) {
|
||||
performUpgrade(sourceName, outName);
|
||||
@@ -629,7 +631,6 @@ public class Main {
|
||||
zfProfile = zfProfile.toLowerCase();
|
||||
|
||||
|
||||
|
||||
// Verify params
|
||||
ensureFileExists(pdfName);
|
||||
ensureFileExists(xmlName);
|
||||
@@ -647,8 +648,7 @@ public class Main {
|
||||
standard = EStandard.despatchadvice;
|
||||
|
||||
zfConformanceLevelProfile = Profiles.getByName(standard, "PILOT", 1);
|
||||
}
|
||||
else if (((format.equals("zf")) && (zfIntVersion == 1))||(format.equals("ox"))) {
|
||||
} else if (((format.equals("zf")) && (zfIntVersion == 1)) || (format.equals("ox"))) {
|
||||
if (format.equals("ox")) {
|
||||
standard = EStandard.orderx;
|
||||
}
|
||||
@@ -769,13 +769,14 @@ public class Main {
|
||||
System.out.println(sr.getSummaryLine());
|
||||
}
|
||||
|
||||
private static void performVisualization(String sourceName, String lang, String outName) {
|
||||
private static void performVisualization(String sourceName, String lang, String outName, boolean intoPDF) {
|
||||
// Get params from user if not already defined
|
||||
if (sourceName == null) {
|
||||
sourceName = getFilenameFromUser("ZUGFeRD XML source", "factur-x.xml", "xml", true, false);
|
||||
} else {
|
||||
System.out.println("ZUGFeRD XML source set to " + sourceName);
|
||||
}
|
||||
if (!intoPDF) {
|
||||
if (lang == null) {
|
||||
try {
|
||||
lang = getStringFromUser("Output language", "en", "en|de|fr");
|
||||
@@ -785,11 +786,18 @@ public class Main {
|
||||
} else {
|
||||
System.out.println("Output language set to " + lang);
|
||||
}
|
||||
}
|
||||
|
||||
if (outName == null) {
|
||||
outName = getFilenameFromUser("HTML target file", "factur-x.html", "html", false, true);
|
||||
String defaultFilename = "factur-x.html";
|
||||
String defaultExtension = "html";
|
||||
if (intoPDF) {
|
||||
defaultFilename = "factur-x.pdf";
|
||||
defaultExtension = "pdf";
|
||||
}
|
||||
outName = getFilenameFromUser("Target file", defaultFilename, defaultExtension, false, true);
|
||||
} else {
|
||||
System.out.println("HTML target set to " + outName);
|
||||
System.out.println("Target set to " + outName);
|
||||
}
|
||||
|
||||
// Verify params
|
||||
@@ -805,6 +813,7 @@ public class Main {
|
||||
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
|
||||
String xml = null;
|
||||
try {
|
||||
if (!intoPDF) {
|
||||
ZUGFeRDVisualizer.Language langCode = ZUGFeRDVisualizer.Language.EN;
|
||||
if (lang.equalsIgnoreCase("de")) {
|
||||
langCode = ZUGFeRDVisualizer.Language.DE;
|
||||
@@ -814,6 +823,9 @@ public class Main {
|
||||
}
|
||||
xml = zvi.visualize(sourceName, langCode);
|
||||
Files.write(Paths.get(outName), xml.getBytes());
|
||||
} else {
|
||||
zvi.toPDF(sourceName, outName);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
@@ -825,6 +837,8 @@ public class Main {
|
||||
}
|
||||
System.out.println("Written to " + outName);
|
||||
|
||||
if (!intoPDF) {
|
||||
|
||||
try {
|
||||
ExportResource("/xrechnung-viewer.css");
|
||||
ExportResource("/xrechnung-viewer.js");
|
||||
@@ -833,6 +847,7 @@ public class Main {
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user