DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Vincent A. Cicirello
Vincent A. Cicirello

Posted on

Combine Multiple PDF Files Into One Using pdfLaTeX

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

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}
Enter fullscreen mode Exit fullscreen mode

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}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

GitHub logo 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:

  1. Make sure you have an up to date LaTeX system installed such as TeX Live.
  2. Read the comments in the file CombinePDFs.tex.
  3. 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.
  4. Run pdflatex CombinePDFs.tex at the command line, which will produce a file named CombinePDFs.pdf.
  5. You can then rename the pdf file, or alternatively, you can name the tex file as desired before you begin.

Where You Can Find Me

On the Web:

Vincent A. Cicirello - Professor of Computer Science

Vincent A. Cicirello - Professor of Computer Science at Stockton University - is a researcher in artificial intelligence, evolutionary computation, swarm intelligence, and computational intelligence, with a Ph.D. in Robotics from Carnegie Mellon University. He is an ACM Senior Member, IEEE Senior Member, AAAI Life Member, EAI Distinguished Member, and SIAM Member.

favicon cicirello.org

Follow me here on DEV:

Follow me on GitHub:

GitHub logo cicirello / cicirello

My GitHub Profile

Vincent A Cicirello

Vincent A. Cicirello

Sites where you can find me or my work
Web and social media Personal Website LinkedIn DEV Profile
Software development Github Maven Central PyPI Docker Hub
Publications Google Scholar ORCID DBLP ACM Digital Library IEEE Xplore ResearchGate arXiv

My bibliometrics

My 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 (1)

Collapse
 
cicirello profile image
Vincent A. Cicirello Author

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.

DEV has this feature:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›