1

I'm in the process of developing a program that basically compiles a bunch of PDF files into 1 book and generates a TOC. Periodically, there are items that they want to appear in the TOC that point to the same PDF file. It could appear at any point in the TOC, so they are not consecutive. I've sorta gotten this to work using labels and \setcounter{page}{\getpagerefnumber{<label>}}, but it seems a bit cludgy, and while the TOC shows a number, it doesn't jump to the correct PDF file. Here's a sample output:


\documentclass[12pt]{report}
\usepackage[final]{pdfpages}
\usepackage{hyperref}
\usepackage{fancyhdr}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{subcaption}
\usepackage{tocloft}
\pdfoptionpdfminorversion 7

\pagestyle{fancy}
\lfoot{\today}
\rfoot{\thepage}
\cfoot{}
\rhead{}
\lhead{\leftmark}
\renewcommand {\headrulewidth}{0.4pt}
\renewcommand {\footrulewidth}{0.4pt}
%
\makeatletter
\setlength{\@fptop}{0pt}
\makeatother
%

\begin{document}\thispagestyle{empty}
\includepdf{title.pdf}
\clearpage\phantomsection
\tableofcontents
\includepdfset{pagecommand=\thispagestyle{fancy}}
\clearpage\phantomsection
\addcontentsline{toc}{chapter}{Section 1}\markboth{Section 1}{}
\begin{center}
\Huge
Section 1
\end{center}
\clearpage\phantomsection
\label{page12345}
\addcontentsline{toc}{section}{2-1/2X1 DOM MAL GALV REDUCER }
\includepdf[width={7.23in},height={9.35in},pages={-}]{ANVILIE00199_17_26_pdf.pdf}
\clearpage\phantomsection
\addcontentsline{toc}{chapter}{Section 2}\markboth{Section 2}{}
\begin{center}
\Huge
Section 2
\end{center}
\setcounter{page}{\getpagerefnumber{page12345}}
\addcontentsline{toc}{section}{2-1/2X1 DOM MAL GALV REDUCER }
\end{document}

EDIT: Just for clarification, here's a booklet generated (http://www.mtncom.net/project-files/231/VTEhz3etqH1nBhbE/). The PDF file for section 1 and 2 are the same, so it should be like:


Section 1                                  3
   blah, blah, blah ...................... 4

Section 2 6 blah, blah, blah ...................... 4

And the blah, blah, blah in Section 2 should take you to page 4 when you click on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.