Ok, here is a quick way to do three tasks at once:
- Combine 400 single-page PDF files.
- Create top level document ToC (table of contents).
- Create a PDF bookmark for each page.
It uses the LaTeX installation.
You start with an empty LaTeX template, for example, the following:
\documentclass[]{article} \usepackage{pdfpages} \usepackage{hyperref} \hypersetup{breaklinks=true, bookmarks=true, pdfauthor={}, pdftitle={}, colorlinks=true, citecolor=blue, urlcolor=blue, linkcolor=magenta, pdfborder={0 0 0}} \begin{document} { \hypersetup{linkcolor=black} \setcounter{tocdepth}{3} % Comment next line in or out if you want a ToC or not: \tableofcontents } %% Here goes your additional code: %% 1 line per included PDF! \end{document}
Now, before the very last line of this template, you insert one line for the external PDF file you want to include.
If you want to generate ToC, it must be formatted as follows:
\includepdf[pages={<pagenumber>},addtotoc{<pagenumber>,<section>,<level>,\ <heading>,<label>}]{pdffilename.pdf}
If you are sure that each attached PDF is a one-page document, it simplifies this:
\includepdf[addtotoc{<pagenumber>,<section>,<level>,\ <heading>,<label>}]]{pdffilename.pdf}
Here, all of the following five parameters for addtotoc are required in the order specified for the files that will be displayed in bookmarks and in ToC. See below below for a specific example:
<pagenumber> : page number of the inserted document to which you want to connect. (In your case, it is always "1" because you only insert single-page documents, however you can insert a 5-page document and a link to page 3 of the inserted PDF file).<section> : The name of the LaTeX section. Maybe section , subsection , subsubsection ... In your case, "section".<level> : LaTeX partition level. In your case, "1".<heading> . This is a string. Used for bookmark text.<label> . This should be unique to each bookmark. Used in a PDF file to go to the correct page when you click a bookmark.
To test this quickly, I used Ghostscript to create 20 one-page PDF documents:
for i in {1..20}; do gs -op${i}.pdf -sDEVICE=pdfwrite \ -c "/Helvetica findfont 30 scalefont setfont \ 100 600 moveto \ (Page ${i}) show \ showpage"; done
With these test files, I could make the lines that need to be inserted into the template, looks like this:
\includepdf[addtotoc={1,section,1,Page 1 (First),p1}]{p1.pdf} \includepdf[addtotoc={1,section,1,Page 2,p2}]{p2.pdf} \includepdf[addtotoc={1,section,1,Page 3,p3}]{p3.pdf} [...] \includepdf[addtotoc={1,section,1,Page 11 (In the Middle),p11}]{p11.pdf} [...] \includepdf[addtotoc={1,section,1,Page 20 (Last),p20}]{p20.pdf}
Save the template with inserted lines, then run the following command twice :
pdflatex template.tex pdflatex template.tex
As a result, the file will have bookmarks similar to this in Preview.app:

Note. LaTeX is available for OSX in two ways:
I will add one or two other methods to add bookmarks on the command line, later or in the next few days if I have more time.
Now it needs to be done, because I never showed it here on SO, AFAICR.
But I thought, because you gave the background โI am combining single-page PDF files and itโs slow, now I want to add bookmarks too ...โ, I could show how to do it using one single method.
TIP . One other way would be to use pdftk , for which IS is available for Mac OS X!