Search code examples
pdf-generationwkhtmltopdfhtml-to-pdf

Syntax for wkhtmltopdf page object


Does anyone know the syntax for adding a page object? I tried the following from the instructions, but it is clearly not a complete example. The same command minus "(page)?" produces a PDF. I'm using wkhtmltopdf version 0.12.5 on a Mac running Catalina 10.15.2. My goal is to combine multiple HTML pages into one PDF. Both Google and SO searches failed to turn up anything relevant to my question.

wkhtmltopdf (page)? pg01.html page1-3.pdf
-bash: syntax error near unexpected token `page'

Solution

  • I see where the confusion is coming from. From the autogenerated documentation:

      A page objects puts the content of a single webpage into the output document.
    
      (page)? <input url/file name> [PAGE OPTION]...
      Options for the page object can be placed in the global options and the page
      options areas. The applicable options can be found in the Page Options and
      Headers And Footer Options sections.
    

    I think that is just saying that the page could be optional, and refer to either the main document or a cover or header document.

    It sounds to me like you want a single PDF that is made up of different HTML documents. I don't believe it's possible to do this with wkhtmltopdf alone, however, you could convert multiple HTML documents or websites to PDFs individually, then combine them with something like PDFtk server when done.

    That would look something like this:

    wkhtmltopdf doc1.html doc1.pdf && \
      wkhtmltopdf doc2.html doc2.pdf && \
      wkhtmltopdf doc3.html doc3.pdf && \
      pdftk doc1.pdf doc2.pdf doc3.pdf cat output final.pdf