Sometimes, PDF files—like those from book chapters—come password-protected to prevent editing, which also stops you from merging them without knowing the password. If printing is allowed, you can work around this by printing the file to PDF, but this creates a new PDF where the text is no longer selectable or searchable. While you could re-OCR the file, a much better solution is to use an old yet powerful tool: Ghostscript, originally developed by Adobe.
Ghostscript allows you to manipulate PDF files easily, including merging multiple PDFs into one. For example, to merge three PDFs named 1.pdf
, 2.pdf
, and 3.pdf
, you can run the following command:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf 1.pdf 2.pdf 3.pdf
Here’s what the parameters mean:-dBATCH
: Tells Ghostscript to process all files and then exit (batch mode).-dNOPAUSE
: Disables pauses between processing each page (no manual intervention required).-q
: Runs the command quietly, suppressing most of the output messages.-sDEVICE=pdfwrite
: Specifies that the output should be written as a PDF.-sOutputFile=merged.pdf
: Defines the name of the resulting merged file.
1.pdf
to 100.pdf
), you can generate the file list dynamically in the command line, like this:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf $(seq -f "%g.pdf" 1 100)
Note that the gs tool takes considerable time to handle so many entries, but this approach saves your time after all.