Browse Source

Add support for ToC options

When creating the command line, all parameters were added before the 'toc' argument.
Therefore, the ToC parameters didn't work (they should be placed after the 'toc' param).
I added a separate tocParams data member with the relevant addTocParam() method.
Oren Cohen 7 years ago
parent
commit
a6b54ac877
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java

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

@@ -28,6 +28,8 @@ public class Pdf {
 
 
     private final Params params;
     private final Params params;
 
 
+    private final Params tocParams;
+
     private final List<Page> pages;
     private final List<Page> pages;
 
 
     private boolean hasToc = false;
     private boolean hasToc = false;
@@ -39,6 +41,7 @@ public class Pdf {
     public Pdf(WrapperConfig wrapperConfig) {
     public Pdf(WrapperConfig wrapperConfig) {
         this.wrapperConfig = wrapperConfig;
         this.wrapperConfig = wrapperConfig;
         this.params = new Params();
         this.params = new Params();
+        this.tocParams = new Params();
         this.pages = new ArrayList<Page>();
         this.pages = new ArrayList<Page>();
     }
     }
 
 
@@ -81,6 +84,10 @@ public class Pdf {
         this.params.add(param, params);
         this.params.add(param, params);
     }
     }
 
 
+    public void addTocParam(Param param, Param... params) {
+        this.tocParams.add(param, params);
+    }
+
     public File saveAs(String path) throws IOException, InterruptedException {
     public File saveAs(String path) throws IOException, InterruptedException {
         File file = new File(path);
         File file = new File(path);
         FileUtils.writeByteArrayToFile(file, getPDF());
         FileUtils.writeByteArrayToFile(file, getPDF());
@@ -120,8 +127,10 @@ public class Pdf {
 
 
         commandLine.addAll(params.getParamsAsStringList());
         commandLine.addAll(params.getParamsAsStringList());
 
 
-        if (hasToc)
+        if (hasToc) {
             commandLine.add("toc");
             commandLine.add("toc");
+            commandLine.addAll(tocParams.getParamsAsStringList());
+        }
 
 
         for (Page page : pages) {
         for (Page page : pages) {
             if (page.getType().equals(PageType.htmlAsString)) {
             if (page.getType().equals(PageType.htmlAsString)) {