Browse Source

adding more docs related to #75

Jhonny Mertz 2 years ago
parent
commit
79c91c12b9

+ 7 - 1
README.md

@@ -33,7 +33,12 @@ In your `pom.xml`:
 Usage and Examples
 ------------
 ```java
-Pdf pdf = new Pdf();
+// Attempt to find the wkhtmltopdf command from OS path
+String executable = WrapperConfig.findExecutable();
+
+// Initialize with the command wrapper
+// Customize the OS command to be called if needed
+Pdf pdf = new Pdf(new WrapperConfig(executable));
 
 pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
 pdf.addPageFromUrl("http://www.google.com");
@@ -45,6 +50,7 @@ pdf.addToc();
 // All options are passed as array, for example:
 pdf.addParam(new Param("--no-footer-line"), new Param("--header-html", "file:///header.html"));
 pdf.addParam(new Param("--enable-javascript"));
+pdf.addParam(new Param("--javascript-delay", "2000"));
 
 // Add styling for Table of Contents
 pdf.addTocParam(new Param("--xsl-style-sheet", "my_toc.xsl"));

+ 18 - 1
src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/integration/PdfIntegrationTests.java

@@ -19,7 +19,6 @@ public class PdfIntegrationTests {
 
     @Test
     public void findExecutable() {
-        WrapperConfig wc = new WrapperConfig();
         //see if executable is installed
         try {
             WrapperConfig.findExecutable();
@@ -149,4 +148,22 @@ public class PdfIntegrationTests {
 
         Assert.assertThat("document should be generated", pdfText, containsString("Google"));
     }
+
+    @Test
+    public void testPdfWithLongParameters() throws Exception {
+        final String executable = WrapperConfig.findExecutable();
+        Pdf pdf = new Pdf(new WrapperConfig(executable));
+        pdf.addPageFromUrl("http://www.google.com");
+
+        pdf.addParam(new Param("--javascript-delay", "2000"));
+
+        pdf.saveAs("output.pdf");
+
+        // WHEN
+        byte[] pdfBytes = pdf.getPDF();
+        PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes));
+        String pdfText = new PDFTextStripper().getText(pdDocument);
+
+        Assert.assertThat("document should be generated", pdfText, containsString("Google"));
+    }
 }