# pdfpages and outline: How to add outline when using pdfpages

I want to add outline for navigating a pdf document. I am inserting pdf pages using includepdf of pdfpages package. How can i do it.

\documentclass[]{article}
\usepackage[]{geometry}
\usepackage[]{pdfpages}
\begin{document}
% add an outline here (LEVEL1, NAME1)
\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 1}

\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 2}

% add an outline here (LEVEL2, NAME2)
\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 3}

\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 4}

% add an outline here (LEVEL3, NAME3)
\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 5}

\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 6}

\begin{document}


Just use the option addtotoc of \includepdf to create labels and section entries. Then include hyperref and these section entries will appear as outlines automatically.

\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref}

\begin{document}

\includepdf[
pages=1-6, fitpaper,
1, section, 1, NAME1, sec:label1,
3, subsection, 2, NAME2, sec:label2,
5, subsubsection, 3, NAME3, sec:label3 }
]{test.pdf}

\end{document}

• why to use section and subsection rather than mentioning only level 1 or 2. what is the use of sec:label1, – Santhosh Aug 22 '20 at 14:11
• You can reference the page with \ref{sec:label1}. – Andreas Matthias Aug 22 '20 at 14:41
• Section name and section level are not the same but are two different beasts according to the standard LaTeX classes. If you really want to know why read the documentation of \@startsection in source2e.pdf. – Andreas Matthias Aug 22 '20 at 14:41

I got the answer at PDF Bookmarks with LaTeX which is mentioned at How to import, export and edit bookmarks of a pdf file?

Use bookmark package and in the document put \bookmark[page=,level=]{title}

\documentclass[]{article}
\usepackage[]{geometry}
\usepackage[]{pdfpages}
\usepackage{bookmark}
\begin{document}
% add an outline here (LEVEL1, NAME1)
\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 1}

\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 2}

% add an outline here (LEVEL2, NAME2)
\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 3}

\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 4}

% add an outline here (LEVEL3, NAME3)
\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 5}

\newgeometry{margin=0}
\includepdfmerge[fitpaper]{test.pdf, 6}

\bookmark[page=1,level=0]{NAME1}
\bookmark[page=3,level=1]{NAME2}
\bookmark[page=5,level=2]{NAME3}

\begin{document}

• This approach will go wrong if you add text at the beginning and forget to adjust the page numbers of the \bookmark commands. – Andreas Matthias Aug 22 '20 at 13:37