Browse Source

split custom wkhtmltopdf command into multiple strings (#77)

Co-authored-by: Jhonny Mertz <jhonnymertz@gmail.com>
Evaldas 2 years ago
parent
commit
694492b83e

+ 1 - 1
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java

@@ -245,7 +245,7 @@ public class Pdf {
             commandLine.addAll(wrapperConfig.getXvfbConfig().getCommandLine());
             commandLine.addAll(wrapperConfig.getXvfbConfig().getCommandLine());
         }
         }
 
 
-        commandLine.add(wrapperConfig.getWkhtmltopdfCommand());
+        commandLine.addAll(Arrays.asList(wrapperConfig.getWkhtmltopdfCommandAsArray()));
 
 
         commandLine.addAll(params.getParamsAsStringList());
         commandLine.addAll(params.getParamsAsStringList());
 
 

+ 3 - 3
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/configurations/WrapperConfig.java

@@ -75,13 +75,13 @@ public class WrapperConfig {
     }
     }
 
 
     /**
     /**
-     * Gets the wkhtmltopdf command to be used while calling wkhtmltopdf
+     * Gets the wkhtmltopdf command as an array to be used while calling wkhtmltopdf
      * It's default is 'wkhtmltopdf'
      * It's default is 'wkhtmltopdf'
      *
      *
      * @return the wkhtmltopdf command
      * @return the wkhtmltopdf command
      */
      */
-    public String getWkhtmltopdfCommand() {
-        return wkhtmltopdfCommand;
+    public String[] getWkhtmltopdfCommandAsArray() {
+        return wkhtmltopdfCommand.split(" ");
     }
     }
 
 
     /**
     /**

+ 21 - 0
src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/integration/PdfIntegrationTests.java

@@ -28,6 +28,27 @@ public class PdfIntegrationTests {
         }
         }
     }
     }
 
 
+    @Test
+    public void getDefaultWkhtmltopdfCommandAsArray() {
+        String installedCommand = WrapperConfig.findExecutable();
+
+        WrapperConfig wc = new WrapperConfig();
+        String[] result = wc.getWkhtmltopdfCommandAsArray();
+
+        Assert.assertEquals(installedCommand, result[0]);
+    }
+
+    @Test
+    public void getCustomWkhtmltopdfCommandAsArray() {
+        WrapperConfig wc = new WrapperConfig("custom wkhtmltopdf command");
+
+        String[] result = wc.getWkhtmltopdfCommandAsArray();
+
+        Assert.assertEquals("custom", result[0]);
+        Assert.assertEquals("wkhtmltopdf", result[1]);
+        Assert.assertEquals("command", result[2]);
+    }
+
     @Test
     @Test
     public void testPdfFromStringTo() throws Exception {
     public void testPdfFromStringTo() throws Exception {