How to use the command 'pdfjoin' (with examples)
pdfjoin
is a command-line utility for merging PDF files, part of the pdfjam
suite of tools. It allows users to combine PDFs in flexible ways, whether merging entire documents, selecting specific pages, or rearranging content. Leveraging the power of LaTeX and its PDF toolkit, pdfjoin
simplifies many tasks that would typically require more complex software. Below are practical examples illustrating different ways to utilize this command.
Use case 1: Merge Two PDFs into One with the Default Suffix “joined”
Code:
pdfjoin path/to/file1.pdf path/to/file2.pdf
Motivation: In many professional or academic settings, you may have separate PDF documents that need to be consolidated into one file for seamless sharing or archiving. For instance, combining related reports or different chapters of a thesis into a single document can facilitate easier handling and presentation.
Explanation:
path/to/file1.pdf
andpath/to/file2.pdf
: These arguments specify the paths to the two PDF files you wish to join.- The command by default appends a suffix “joined” to the resultant file, which indicates the files were merged. No separate output file is defined explicitly here, so it defaults to this naming.
Example Output:
Upon running the command, you will get a new PDF file named file1-file2-joined.pdf
in the current working directory. This file contains the contents of both file1.pdf
and file2.pdf
, placed sequentially.
Use case 2: Merge the First Page of Each Given File Together
Code:
pdfjoin path/to/file1.pdf path/to/file2.pdf ... 1 --outfile output_file
Motivation: You might be in a scenario where you only need the introductory pages from several documents, perhaps to create a table of contents or an overview file. Extracting and merging just the first pages can streamline this task efficiently.
Explanation:
path/to/file1.pdf
,path/to/file2.pdf
, etc.: These are the PDFs from which the first page will be extracted.1
: Indicates that only the first page of each specified PDF file should be included in the final document.--outfile output_file
: This option determines the name of the output file. In this context, it names the resultant documentoutput_file.pdf
.
Example Output:
As a result, you will have an output_file.pdf
that contains only the first page from each of the input PDFs, ordered as specified in the command.
Use case 3: Save Pages 3 to 5 Followed by Page 1 to a New PDF with Custom Suffix
Code:
pdfjoin path/to/file.pdf 3-5,1 --suffix rearranged
Motivation: Imagine you have a PDF and need to rearrange specific pages — for example, putting introductory notes from page 1 at the end after showcasing contents from pages 3 to 5. This command allows you to reorganize pages precisely to meet particular presentation or printing needs.
Explanation:
path/to/file.pdf
: The PDF from which pages will be selected.3-5,1
: Specifies the page range from 3 to 5 followed by page 1, indicating the order of selection from the original PDF.--suffix rearranged
: Sets a custom suffix called “rearranged” for the output file to indicate its specific organization.
Example Output:
The output will be a new PDF named file-rearranged.pdf
containing pages 3 to 5 followed by page 1 from the original document.
Use case 4: Merge Page Subranges from Two PDFs
Code:
pdfjoin /path/to/file1.pdf 2- file2 last-3 --outfile output_file
Motivation: There are times when you only want to compile certain sections of multiple reports, such as the conclusions from one and the appendices from another. This command can facilitate the custom compilation without editing each file separately.
Explanation:
/path/to/file1.pdf
: Path to the first PDF file.2-
: Indicates selecting pages from page 2 to the last page offile1.pdf
.file2 last-3
: This part means selecting fromfile2
only the last three pages.--outfile output_file
: Indicates the name of the combined output PDF.
Example Output:
The command generates a PDF named output_file.pdf
containing pages 2 to the end from file1.pdf
, continued by the last three pages of file2
.
Conclusion:
pdfjoin
is a powerful tool that can significantly enhance productivity when working with multiple PDF files. Its ability to specify page ranges, output files, and file suffixes offers users control over how documents are merged. Whether for academic, corporate, or personal use, mastering pdfjoin
can streamline document management tasks efficiently.