The Portable Document Format (PDF) is perhaps one of the most widespread file formats for sharing documents.
Even my mom, far from being a computer expert, can recognize the format in which she receives school notices via email.
Its popularity, combined with the fact that a browser is enough to view them, makes it the ideal choice for exporting your work without worrying about compatibility issues.
But you already know that.
What I want to collect on this page is a series of useful commands for manipulating PDF files from the command line, instead of relying on websites that offer dubious privacy guarantees.
Not to mention that, by working locally, you have the ability to automate the process and manipulate a large number of files in a few seconds.
Useful commands
# Quick method to concatenate multiple PDF files into a single PDF
pdfunite [file1.pdf file2.pdf ...] out.pdf
# Example:
pdfunite chapter1.pdf chapter2.pdf chapter3.pdf complete_book.pdf
# More general method to concatenate multiple PDF files into a single PDF
qpdf --empty --pages [file1.pdf start-end file2.pdf start-end ...] out.pdf
# Example:
qpdf --empty --pages file1.pdf 1-8 file2.pdf 1 file1.pdf 10-16 file3.pdf 1 file1.pdf 18-19 -- out.pdf
# Convert images to PDF
img2pdf image1.jpg [--imgsize <width>x<height>] -o out.pdf
# Example:
img2pdf image1.jpg --imgsize 33.9cmx20cm -o out.pdf
# Extract all pages of a PDF as PNG images
pdfimages -png in.pdf out_prefix
# Example:
pdfimages -png file1.pdf img-
Da Reveal.js a PDF
Reveal.js is a popular framework for creating HTML presentations.
Normally, it’s enough to visit the presentation URL and add ?print-pdf at the end to get a PDF version of the presentation.
However, this method doesn’t always work, especially when using advanced features like fragments or animations.
In these cases, an excellent alternative is to use Decktape.
# Convert a Reveal.js presentation to PDF
decktape reveal url out.pdf [--fragments] [--screenshots]
# Example:
decktape reveal http://localhost:8000/presentation.html out.pdf --fragments --screenshots