How to Use the Command 'pdfjam' (with Examples)
The pdfjam
command is a versatile tool that acts as a shell frontend for the LaTeX pdfpages
package. It’s primarily used for manipulating PDF files in a variety of ways, such as merging, rearranging, or overlaying documents. This utility is helpful for those who work with PDFs regularly and require a streamlined method for organizing and modifying their contents. Below we explore several practical use cases to illustrate the command’s capabilities.
Use Case 1: Merging Two (or More) PDFs
Code:
pdfjam path/to/file1.pdf path/to/file2.pdf --outfile path/to/output_file.pdf
Motivation: Merging multiple PDF files into a single document can be incredibly useful when compiling reports, portfolios, or presentations from separate files. By combining multiple PDFs into one, you streamline file management and sharing efforts.
Explanation:
path/to/file1.pdf
andpath/to/file2.pdf
: These are the input PDF files that you want to merge.--outfile path/to/output_file.pdf
: This option specifies the output file, which will be the merged result of the input PDFs.
Example Output: After executing the command, you’ll have a single PDF located at path/to/output_file.pdf
containing the combined pages from file1.pdf
and file2.pdf
.
Use Case 2: Merging the First Page of Each File Together
Code:
pdfjam files... 1 --outfile path/to/output_file.pdf
Motivation: This use case is beneficial when you want to create a summary document that extracts and merges only the first pages of several documents, such as title pages of papers or cover letters.
Explanation:
files...
: This denotes a placeholder for any number of files you intend to process.1
: This specifies that only the first page of each input file should be included in the result.--outfile path/to/output_file.pdf
: Defines the output file that will contain the first pages from each listed PDF.
Example Output: The resultant PDF located at path/to/output_file.pdf
contains just the first page from each selected PDF file.
Use Case 3: Merging Subranges from Two PDFs
Code:
pdfjam path/to/file1.pdf 3-5,1 path/to/file2.pdf 4-6 --outfile path/to/output_file.pdf
Motivation: When you wish to merge specific pages from two PDF files, such as combining the executive summary and conclusion from separate reports, focusing on particular subranges is key.
Explanation:
path/to/file1.pdf 3-5,1
: This specifies that pages 3 to 5 and page 1 fromfile1.pdf
are to be included.path/to/file2.pdf 4-6
: Denotes that pages 4 to 6 fromfile2.pdf
should be included.--outfile path/to/output_file.pdf
: Designates the output file where the specified pages will be merged.
Example Output: The specified pages from both input PDFs will be compiled into a single document located at path/to/output_file.pdf
.
Use Case 4: Signing an A4 Page with a Scanned Signature by Overlaying
Code:
pdfjam path/to/file.pdf path/to/signature --fitpaper true --outfile path/to/signed.pdf --nup "1x2" --delta "0 -842pt"
Motivation: Inserting a digital signature onto a PDF is a common requirement for document authentication and verification, such as signing contracts or official forms.
Explanation:
path/to/file.pdf
: Path to the PDF that needs to be signed.path/to/signature
: The file path of the scanned signature.--fitpaper true
: Ensures all content fits on the specified paper size.--outfile path/to/signed.pdf
: Specifies the output PDF file, which will be the document with an overlayed signature.--nup "1x2"
: Tells the system to arrange files in a layout of 1 page wide by 2 pages high.--delta "0 -842pt"
: Adjusts the position by 842 points in height, compensating for A4 size.
Example Output: The output file, path/to/signed.pdf
, will have the signature overlayed on each page, accurately placed as specified by the dimensional adjustments.
Use Case 5: Arranging Pages in a Fancy 2x2 Grid
Code:
pdfjam path/to/file.pdf --nup 2x2 --suffix 4up --preamble '\usepackage{fancyhdr} \pagestyle{fancy}'
Motivation: Arranging PDF pages into a grid format is often utilized in presentations and document compilations when visual aesthetics and compactness are priorities.
Explanation:
path/to/file.pdf
: The file whose pages need rearranging.--nup 2x2
: Specifies arranging the pages into a grid of 2 rows by 2 columns.--suffix 4up
: Produces an output file named with a-4up
suffix to distinguish it.--preamble '\usepackage{fancyhdr} \pagestyle{fancy}'
: Adds Latex-like fancy headers, created via custom styling.
Example Output: The output, named file-4up.pdf
, will display pages from the input PDF in an organized 2x2 arrangement with added headers.
Use Case 6: Reversing the Order of Pages and Concatenating PDFs
Code:
pdfjam {{files...}} {{last-1}} --suffix {{reversed}}
Motivation: Reversing page order can be vital for preparing documents for reversing printing tasks, or simply as a feature requirement in archival procedures.
Explanation:
{{files...}}
: Placeholder for any files where page order is to be reversed.{{last-1}}
: Commands the utility to reverse pages from last to first.--suffix {{reversed}}
: Appends the-reversed
suffix to the output filename to indicate the operation performed.
Example Output: The reversed-page order of each input PDF will be concatenated into singular outputs named with a -reversed
suffix, maintaining clarity of process.
Conclusion
As demonstrated, the pdfjam
tool is proficient in handling multiple PDF manipulation tasks with ease. Whether merging, rearranging, or overlaying documents, it provides a powerful, command-line based solution for comprehensive PDF management. With these examples, users are equipped with practical techniques to manage PDF document workflows effectively.