Wednesday, February 2, 2022

[SOLVED] Using wkhtmltopdf to pull individual pages

Issue

I'm trying to convert a HTML page to a document but they are all on individual pages for example

http://www.website.co.uk/example/html5forwebkit.html?page=32

If i run the standard command i just get one page, is there a shortcut command to pull every page i need? there is 450 pages and I want them all to be on the same PDF file


Solution

What you can do is to create a loop and make a PDF of each page using wkhtmltopdfand then merge those seperate PDFs together using pdfunite.

# Change the values to your liking
#            ↓  ↓↓↓
for page in {1..450};do
    wkhtmltopdf "http://www.website.co.uk/example/html5forwebkit.html?page=$page" page_$page.pdf

    # Optional 'sleep' so that you dont end up DOSing the site
    sleep 0.5
done

# Merge the PDFs into one
pdfunite page_*.pdf out.pdf


Answered By - Siddharth Dushantha
Answer Checked By - Cary Denson (WPSolving Admin)