diff --git a/src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java b/src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java index 3f3d726..d68ec8f 100644 --- a/src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java +++ b/src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java @@ -54,6 +54,8 @@ public class Pdf { private File tempDirectory; + private String outputFilename = null; + private List successValues = new ArrayList(Arrays.asList(0)); public Pdf() { @@ -153,6 +155,13 @@ public void setTempDirectory(File tempDirectory) { this.tempDirectory = tempDirectory; } + /** + * Executes the wkhtmltopdf into standard out and captures the results. + * @param path The path to the file where the PDF will be saved. + * @return + * @throws IOException + * @throws InterruptedException + */ public File saveAs(String path) throws IOException, InterruptedException { File file = new File(path); FileUtils.writeByteArrayToFile(file, getPDF()); @@ -160,6 +169,20 @@ public File saveAs(String path) throws IOException, InterruptedException { return file; } + /** + * Executes the wkhtmltopdf saving the results directly to the specified file path. + * @param path The path to the file where the PDF will be saved. + * @return + * @throws IOException + * @throws InterruptedException + */ + public File saveAsDirect(String path)throws IOException, InterruptedException { + File file = new File(path); + outputFilename = file.getAbsolutePath(); + getPDF(); + return file; + } + public byte[] getPDF() throws IOException, InterruptedException, PDFExportException { ExecutorService executor = Executors.newFixedThreadPool(2); @@ -191,7 +214,7 @@ public byte[] getPDF() throws IOException, InterruptedException, PDFExportExcept } } - private String[] getCommandAsArray() throws IOException { + protected String[] getCommandAsArray() throws IOException { List commandLine = new ArrayList(); if (wrapperConfig.isXvfbEnabled()) { @@ -219,7 +242,7 @@ private String[] getCommandAsArray() throws IOException { commandLine.add(page.getSource()); } } - commandLine.add(STDINOUT); + commandLine.add( (null != outputFilename) ? outputFilename : STDINOUT); logger.debug("Command generated: {}", commandLine.toString()); return commandLine.toArray(new String[commandLine.size()]); }