Class Pdf


  • public class Pdf
    extends Object
    Represents a Pdf file and wraps up the wkhtmltopdf processing
    • Method Detail

      • addPage

        @Deprecated
        public void addPage​(String source,
                            PageType type)
        Deprecated.
        Use the specific type method to a better semantic
        Add a page to the pdf
      • addPageFromUrl

        public void addPageFromUrl​(String source)
        Add a page from an URL to the pdf
      • addPageFromString

        public void addPageFromString​(String source)
        Add a page from a HTML-based string to the pdf
      • addPageFromFile

        public void addPageFromFile​(String source)
        Add a page from a file to the pdf
      • addToc

        public void addToc()
      • addParam

        public void addParam​(Param param,
                             Param... params)
      • addTocParam

        public void addTocParam​(Param param,
                                Param... params)
      • setTimeout

        public void setTimeout​(int timeout)
        Sets the timeout to wait while generating a PDF, in seconds
      • setAllowMissingAssets

        public void setAllowMissingAssets()
        wkhtmltopdf often returns 1 to indicate some assets can't be found, this can occur for protocol less links or in other cases. Sometimes you may want to reject these with an exception which is the default, but in other cases the PDF is fine for your needs. Call this method allow return values of 1.
      • getAllowMissingAssets

        public boolean getAllowMissingAssets()
      • setSuccessValues

        public void setSuccessValues​(List<Integer> successValues)
        In standard process returns 0 means "ok" and any other value is an error. However, wkhtmltopdf uses the return value to also return warning information which you may decide to ignore (@see setAllowMissingAssets)
        Parameters:
        successValues - The full list of process return values you will accept as a 'success'.
      • setTempDirectory

        public void setTempDirectory​(File tempDirectory)
        Sets the temporary folder to store files during the process Default is provided by #File.createTempFile()
        Parameters:
        tempDirectory -
      • saveAsDirect

        public File saveAsDirect​(String path)
                          throws IOException,
                                 InterruptedException
        Executes the wkhtmltopdf saving the results directly to the specified file path.
        Parameters:
        path - The path to the file where the PDF will be saved.
        Returns:
        the pdf file saved
        Throws:
        IOException - when not able to save the file
        InterruptedException - when the PDF generation process got interrupted
      • getCommandAsArray

        protected String[] getCommandAsArray()
                                      throws IOException
        Get command as array string Note: htmlAsString pages are first store into a temp file, then the location is used in the wkhtmltopdf command this is a workaround to avoid huge commands
        Returns:
        the wkhtmltopdf command as string array
        Throws:
        IOException - when not able to save temporary files from htmlAsString
      • cleanAllTempFiles

        public void cleanAllTempFiles()
        Cleans up all the files generated by the library.
      • getCommand

        public String getCommand()
                          throws IOException
        Gets the final wkhtmltopdf command as string
        Returns:
        the generated command from params
        Throws:
        IOException - when not able to save temporary files from htmlAsString