Typevia
Format Conversion

Introduction to External PDFs in LaTeX

When creating documents in LaTeX, you often need to include content that already exists in PDF format. This might include a signed certificate, a data sheet, a published research paper, or even a cover page designed in another software.

While the standard graphicx package allows you to include a PDF as an image using \includegraphics, it is limited because it usually only imports the first page and treats it as a single graphic element. To handle multi-page PDFs or to insert full pages seamlessly into your document, the pdfpages package is the industry standard.

In this guide, you will learn how to professionally merge external PDF documents into your LaTeX projects while maintaining control over layout and page selection.

Getting Started: The pdfpages Package

To begin including external PDFs, you must include the pdfpages package in your document's preamble. This package internally loads the graphicx package, so you don't need to worry about conflicts between the two.

Basic Setup

Add the following line to your preamble (before \begin{document}):

\usepackage{pdfpages}

Once the package is loaded, you gain access to the primary command: \includepdf[options]{filename}.

Note: Ensure that the PDF file you want to include is in the same folder as your .tex file, or provide a relative path (e.g., figures/document.pdf). Avoid using spaces in your filenames, as this can cause errors in some LaTeX distributions.


Basic Usage and Page Selection

The most common use case is inserting all pages or specific pages of an external document. By default, if you use the command without any options, LaTeX will only include the first page of the external PDF.

Example 1: Including All Pages

To include every page of an external document, use the pages=- option.

\documentclass{article}
\usepackage{pdfpages}

\begin{document}

\section{Appended Report}
The following pages contain the full laboratory report.

% Include every page of the external PDF
\includepdf[pages=-]{lab-report.pdf}

\end{document}

Selecting Specific Pages

You can precisely control which pages are imported using the pages key. You can specify individual pages, ranges, or a combination of both.

  • pages={1}: Only page 1 (default).
  • pages={3-5}: Pages 3, 4, and 5.
  • pages={1, 3, 8-10}: Pages 1, 3, 8, 9, and 10.
  • pages={-}: All pages.
  • pages={last-1}: Pages in reverse order from the end to the beginning.
\includepdf[pages={1, 4-6, 9}]{appendices.pdf}

Controlling Layout and Appearance

The pdfpages package offers several options to adjust how the external pages appear within your document.

1. Handling Page Orientation

If your source PDF is in landscape orientation, but your LaTeX document is portrait, you can use the landscape option to rotate the included page.

\includepdf[pages={1}, landscape=true]{horizontal-chart.pdf}

2. Multi-page Layout (N-up)

You can arrange multiple pages from the external PDF onto a single page of your LaTeX document. This is often called "N-up" printing. This is controlled by the nup option, which takes the format nup=XyY (columns x rows).

% This will place 4 pages (2 columns, 2 rows) on a single LaTeX page
\includepdf[pages={1-4}, nup=2x2]{handout.pdf}

3. Adding a Frame

Sometimes it is helpful to add a thin border around the included PDF pages, especially if the PDF has a white background that blends into the LaTeX page.

\includepdf[pages={1}, frame=true]{certificate.pdf}

Integrating PDFs into the Document Structure

By default, \includepdf creates a new page for every imported page. However, you might want these pages to appear in your Table of Contents (ToC) or have specific headers and footers.

Adding to Table of Contents

To make an included PDF appear in your Table of Contents, use the addtotoc option. The syntax is: addtotoc={page number, section type, level, heading, label}

\includepdf[pages={1}, addtotoc={1, section, 1, Supplementary Materials, sec:supp}]{supplement.pdf}

Maintaining Page Styles

If you want to keep your document's headers and footers (like page numbers) on the pages where the PDF is inserted, use the pagecommand option. By default, pdfpages sets the page style to empty.

% This keeps the standard header/footer on the included PDF pages
\includepdf[pages={1-3}, pagecommand={\thispagestyle{headings}}]{report.pdf}

% Use an empty group {} to keep the current page style active
\includepdf[pages={-}, pagecommand={}]{document.pdf}

Best Practices and Common Pitfalls

1. File Size and Resolution

Including many high-resolution PDFs can significantly increase the size of your final output file. If you are preparing a document for the web, consider compressing your source PDFs before compiling the LaTeX document.

Warning: When you include a PDF using pdfpages, most interactive elements like internal hyperlinks, form fields, and annotations in the source PDF are lost. The imported content is treated essentially as a high-quality graphic.

3. Consistent Page Sizes

If your external PDF has a different page size (e.g., A4) than your LaTeX document (e.g., Letter), pdfpages will by default scale the included page to fit your document's paper size. You can control this behavior using the scale option:

% Scales the included PDF to 80% of its original size
\includepdf[pages={1}, scale=0.8]{large-drawing.pdf}

4. The "File Not Found" Error

Ensure your filenames do not contain spaces or multiple dots.

  • Bad: Final Report Ver. 2.pdf
  • Good: final-report-v2.pdf

Summary Example

Here is a comprehensive example combining several concepts discussed above:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pdfpages}
\usepackage{hyperref}

\begin{document}

\tableofcontents

\section{Introduction}
This document merges various project components.

\section{Project Deliverables}
Below you will find the signed agreement and the technical drawings.

% Including a specific page, adding it to ToC, and keeping page numbers
\includepdf[
    pages={1}, 
    pagecommand={\thispagestyle{plain}}, 
    addtotoc={1, subsection, 2, Signed Agreement, sec:agreement},
    frame=true
]{legal-docs.pdf}

% Including a landscape page resized to 90%
\includepdf[
    pages={5}, 
    landscape=true, 
    scale=0.9
]{blueprints.pdf}

\end{document}

By mastering the pdfpages package, you can use LaTeX as a powerful tool for document assembly, ensuring that all your external resources are professionally integrated into a single, cohesive file.