How to insert a PDF file inside a document


Here we are going to explore a couple of ways in which we can insert an independent PDF file inside a LaTeX document. There are mainly two possibilities that produce slightly different outputs: using the pdfpages packageOpens in a new tab. and using the graphicx packageOpens in a new tab..

1. Insert PDF pages in LaTeX

If what we want is the PDF to appear as an integral part of our document, we will have to use the \includepdf command from the pdfpages package.

This command accepts one mandatory argument with the name of the PDF file (or its path, if the file is not in the current working directory) and one optional argument that indicates the range of pages to be inserted. If we want to insert the whole document, this argument can be left blank.

For example:

\includepdf[pages={1,3,5-7}]{mypdf.pdf}

will insert pages 1,3,5,6 and 7 of the document mypdf.pdf. We can also insert blank pages, using {}. Here is an example:

\includepdf[pages={1-3,{},8,10-12}]{mypdf.pdf}

this will insert pages 1,2 and 3, then a blank page, and finally pages 8,10,11,12 of mypdf.pdf.

2. Insert PDF as a box in LaTeX

A different approach is to insert the PDF not as an integral part of our document, but rather as a box, which can be made into a floating figure, for example. To do so, we can use the common graphicx package and its \includegraphics command, with the difference that instead of inserting an image we will be inserting a PDF document.

The drawback of this approach is that only the first page of the document will be inserted, so this is only useful for documents with a single page, or if we divide the PDF into multiple parts and insert them one by one.

For example, you can see here how to insert the first page of the PDF fileOpens in a new tab. using \includegraphics:

% Insert PDF in LaTeX 2
\documentclass{article}

% Required package
\usepackage{graphicx}

\begin{document}

\begin{figure}[htpb]
    \centering
    \includegraphics[width=0.8\textwidth]{tikzpgf.pdf}
    \caption{The first page of the \texttt{tikz} reference manual.}
    \label{fig:tikzpgf}
\end{figure}

\end{document}

The output produced is shown in the following image:

Inserting the first page of a PDF document inside a LaTeX document as a floating object.

Observe how we have wrapped the \includegraphics inside a figure environment, like it, is usually done when inserting graphical content, to transform it into a floating object.

We reached the end of this tutorial, If you have any remarks or suggestions, please feel free to reach us via email at admin@latex-tutorial.comOpens in a new tab.

Recent Posts