I use LaTeX for virtually all written documents I produce. It is a necessity when writing academic papers in computer science journals and conferences. But I also use it to format my CV, to write recommendation letters for students, among many other things. It is ideal for any writing that involves formatting mathematics, and it greatly simplifies bibliography generation. Occasionally, it is necessary to produce a single pdf from a combination of documents, some of which may be beyond my control, or may be in a format that I cannot easily embed within another. For example, perhaps I need to include an appendix written by someone else in something horrid like Microsoft Word. The solution is to convert each document to a pdf, as a common format, and then combine into a single file. LaTeX is natively compiled into pdf, and just about any other format can generally convert to pdf without much difficulty.
So you have multiple pdf files that you want to combine into one, but you don't have a version of Acrobat that will do this. Here's an easy way to combine multiple pdf files using pdfLaTeX. If you don't use LaTeX, don't worry about it. You don't really need to know LaTeX to use this trick, and I have a repository on GitHub with a LaTeX file you can edit with the details of the pdfs you want to combine. It doesn't matter how the original pdf files were produced.
Table of Contents:
- How to Combine Multiple PDFs with pdfLaTeX
- GitHub Repository with the full example that you can download and edit as needed
- Where You Can Find Me
How to Combine Multiple PDFs with pdfLaTeX
Here are the steps to combining multiple pdfs using pdfLaTeX.
Step 0: Install a LaTeX Distribution
If you don't have LaTeX installed on your system already, then you'll need to begin by installing a LaTeX distribution. For example, TeX Live is a good choice.
Step 1: Create a LaTex Source File
Create a LaTeX source file with a tex
extension and named how you want the final pdf
named (other than extension). For example, if you want your pdf named combined.pdf
, then name your tex file combined.tex
. It will save you from renaming files later.
In that combined.tex
file (or whatever you named it), add the following with your favorite text editor.
\documentclass[11pt,letterpaper]{article}
\usepackage[final]{pdfpages}
\begin{document}
% The following lines are the only ones you need to edit.
\includepdf[pages=-]{file1.pdf}
\includepdf[pages=-]{file2.pdf}
\includepdf[pages=-]{file3.pdf}
\end{document}
The above example combines three pdf files file1.pdf
, file2.pdf
, and file3.pdf
in their entirety and in that order. Simply edit these lines with the names of your pdf files.
A statement like: \includepdf[pages=-]{file1.pdf}
will add the entire contents of file1.pdf
to the pdf that results. If you want to include only part of one of the files, you can specify a page range. For example, perhaps you want all of file1.pdf
, but only pages 3 to 7 of file2.pdf
, and then all of file3.pdf
. You can accomplish something like that with the following.
\documentclass[11pt,letterpaper]{article}
\usepackage[final]{pdfpages}
\begin{document}
% The following lines are the only ones you need to edit.
\includepdf[pages=-]{file1.pdf}
\includepdf[pages=3-7]{file2.pdf}
\includepdf[pages=-]{file3.pdf}
\end{document}
Step 2: Run pdfLaTeX.
You can now use pdfLaTeX to combine the pdfs. At the command line, in the directory containing the LaTeX source file you created above and your existing pdfs, run the following (change the combined.tex
file to whatever filename you used above):
pdflatex combined.tex
This will produce a pdf named combined.pdf
.
GitHub Repository
I have a GitHub repository with a LaTeX file that you can download and edit with the details of your pdfs to get you started.
cicirello / combine-pdf-files
Use pdflatex to combine multiple pdf files
combine-pdf-files
Use pdflatex to combine multiple pdf files with the following steps:
- Make sure you have an up to date LaTeX system installed such as TeX Live.
- Read the comments in the file CombinePDFs.tex.
- Edit the lines in that file where indicated with the names of the pdfs you want to combine in the order you want them to appear in the result, including specifying page ranges if you don't want the entire pdf files.
- Run
pdflatex CombinePDFs.tex
at the command line, which will produce a file namedCombinePDFs.pdf
. - You can then rename the pdf file, or alternatively, you can name the
tex
file as desired before you begin.
Blog Post Explaining Usage
Combine Multiple PDF Files Into One Using pdfLaTeX, posted on DEV on September 14, 2022.
Where You Can Find Me
On the Web:
Follow me here on DEV:
Follow me on GitHub:
Vincent A Cicirello
View My Detailed GitHub Activity
If you want to generate the equivalent to the above for your own GitHub profile, check out the cicirello/user-statistician GitHub Action.
Top comments (2)
My opening paragraph may inadvertently imply that you have a base document formatted in LaTeX. The trick explained in this post applies no matter what any of the documents were formatted in. The only LaTeX required is the few lines in the template in the examples.
Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more