Turning websites into pdf files, how can this be automated with KM?

Thinking about purchasing KM if it can help automate turning websites into each page a PDF file. So what I've done is downloaded all the pages and have hundreds of "index.html" files. My thinking is the best way to get these to PDF would be the OSX "print to pdf" dialogue. I could bulk open these as tabs in Firefox or whatnot then print each to PDF, but that would be a slog on hundreds of pages weekly.

Someone suggested using terminal with the code below, but for some reason can't get it outputting to PDF. Is there some way KM could take advantage of that code and make it easier to use - drag n drop etc? Or even bulk print to PDF all open tabs in FF macro?


for filename in file:///$HOME/somefolder/*.html; do


chromium-browser --headless --disable-gpu --print-to-pdf "${stub}.html"

I think the easiest way what you could do is open all pages as tabs and then make a Keyboard Maestro macro to just repeat CMD+P, Enter, CMD+W and stop once no tabs are open.

The better version would be as you suggested with a script that calls headless chrome. I think your code did not work as print-to-pdf expects an argument to specify the filename+path.
Out of curiosity I just tried it. The below worked for me (saves website directly to pdf) ā€“ paths must be adjusted to your filesystem.
alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"

chrome --headless --print-to-pdf="/Users/stockholm/test.pdf" https://google.com

I think would also work the same for local html sites (just replace 'https://google.com' with local path).
Also with Keyboard Maestro you definitely could setup something that repeats this script for every selected file in finder. Or if you want to do it directly maybe make a shortcut so Keyboard Maestro gets the url of the current website and runs the script with it.

1 Like

Thanks much for your detailed reply! Will give it a try this evening when Iā€™m back on the laptop.