How to use the command pdfjam (with examples)

How to use the command pdfjam (with examples)

pdfjam is a shell frontend for the LaTeX pdfpages package that allows for mingling PDF files. It can be used to merge, rearrange and manipulate PDF files in various ways.

Use case 1: Merge two (or more) PDFs

Code:

pdfjam path/to/file1.pdf path/to/file2.pdf --outfile path/to/output_file.pdf

Motivation: This use case is useful when you want to combine multiple PDF files into a single file.

Explanation: In this command, path/to/file1.pdf and path/to/file2.pdf are the paths to the PDF files that you want to merge. --outfile specifies the output file path where the merged PDF will be saved.

Example output: The PDF files file1.pdf and file2.pdf will be merged into a single PDF file named output_file.pdf.

Use case 2: Merge the first page of each file together

Code:

pdfjam files... 1 --outfile path/to/output_file.pdf

Motivation: This use case is useful when you want to create a new PDF file containing only the first page of multiple existing PDF files.

Explanation: In this command, files... represents the paths to the PDF files that you want to merge. 1 is used to specify that only the first page of each file should be merged. --outfile specifies the output file path where the merged PDF will be saved.

Example output: The first page of each PDF file will be merged into a single PDF file named output_file.pdf.

Use case 3: Merge 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: This use case is useful when you want to merge specific page ranges from two PDF files into a single file.

Explanation: In this command, path/to/file1.pdf and path/to/file2.pdf are the paths to the PDF files that you want to merge. 3-5,1 specifies to include pages 3 to 5 and page 1 from file1.pdf, and 4-6 specifies to include pages 4 to 6 from file2.pdf. --outfile specifies the output file path where the merged PDF will be saved.

Example output: Pages 3 to 5 and page 1 from file1.pdf and pages 4 to 6 from file2.pdf will be merged into a single PDF file named output_file.pdf.

Use case 4: Sign an A4 page with a scanned signature by overlaying them

Code:

pdfjam path/to/file.pdf path/to/signature --fitpaper true --outfile path/to/signed.pdf --nup "1x2" --delta "0 -842pt"

Motivation: This use case is useful when you want to sign a document using a scanned signature and overlay it on a page.

Explanation: In this command, path/to/file.pdf is the path to the PDF file to be signed, and path/to/signature is the path to the scanned signature image. --fitpaper true scales the signature to fit the page. --outfile specifies the output file path where the signed PDF will be saved. --nup "1x2" arranges the signature and page in a 1 by 2 grid. --delta "0 -842pt" adjusts the position of the signature.

Example output: The scanned signature will be overlaid on an A4 page, and the signed PDF will be saved as signed.pdf.

Use case 5: Arrange the pages from the input file into a fancy 2x2 grid

Code:

pdfjam path/to/file.pdf --nup 2x2 --suffix 4up --preamble '\usepackage{fancyhdr} \pagestyle{fancy}'

Motivation: This use case is useful when you want to arrange the pages of a PDF file into a fancy 2x2 grid.

Explanation: In this command, path/to/file.pdf is the path to the PDF file to be rearranged. --nup 2x2 arranges the pages in a 2 by 2 grid. --suffix 4up adds the “4up” suffix to the output file name. --preamble allows you to specify any additional LaTeX preamble code.

Example output: The pages from file.pdf will be arranged into a 2x2 grid, and the output file will have the suffix “4up”.

Use case 6: Reverse the order of pages within each given file and concatenate them

Code:

pdfjam {{files...}} {{last-1}} --suffix {{reversed}}

Motivation: This use case is useful when you want to reverse the order of pages within each given file and concatenate them into a single PDF file.

Explanation: In this command, {{files...}} represents multiple PDF files to be processed. {{last-1}} is used to select the second-to-last page of each file. --suffix {{reversed}} adds the “reversed” suffix to the output file name.

Example output: The pages within each given file will be reversed in order and concatenated into a single PDF file with the suffix “reversed”.

Conclusion:

In this article, we have explored various use cases of the pdfjam command. We have seen how to merge PDFs, merge specific page ranges, arrange pages into grids, sign documents with scanned signatures, and reverse the order of pages. With these examples, you can now effectively manage and manipulate your PDF files using the pdfjam command.

Related Posts

How to use the command git paste (with examples)

How to use the command git paste (with examples)

Git paste is a command that allows you to send commits to a pastebin site using pastebinit.

Read More
A Guide to Using the `rustup self` Command (with examples)

A Guide to Using the `rustup self` Command (with examples)

Introduction The rustup self command is a powerful tool that allows users to modify their rustup installation.

Read More
How to Use the asdf Command (with examples)

How to Use the asdf Command (with examples)

asdf is a command-line interface that helps manage different versions of packages.

Read More