Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to merge multiple pdf's into a single PDF with Table Of Contents sections

Will have 50-100 single PDF's that we'll be generating with a php script. PDF's are generally grouped into groups of 10-20. Each group needs to have it's own Table of Contents or Index, and then there also needs to be a Master Table of Contents or Index at the beginning.

Or if that is too difficult we could get away with a single Table of Contents at the beginning.

What's the best way to go about this?

Will we need to create the Table of Contents and then export that to PDF and append it to the beginning and mash the rest of the files after that? Or is there a better solution?

And what's the best tool for us to merge the pdf's?

Will be running on a Linux server.

like image 871
Jason Avatar asked Mar 10 '10 17:03

Jason


People also ask

How do I combine PDF and table of contents?

In Adobe Acrobat, select "Plug-Ins > Merge Documents > Merge Documents into Single Document..." from the main menu to open the "Merge Documents Settings" dialog. Select the desired merge operation type and use the "Add Document(s)/Folder..." buttons to choose files to be merged.

Can you combine multiple PDFs into a single PDF?

Open Acrobat to combine files: Open the Tools tab and select "Combine files." Add files: Click "Add Files" and select the files you want to include in your PDF. You can merge PDFs or a mix of PDF documents and other files.

How do I combine PDF files without losing bookmarks?

Click the Options button. Check Add file names as bookmarks. Click OK. Select where you want to save the combined file and enter a name for the file.

How do I make a collage of multiple PDFs into one?

Select the files you want to merge using the Acrobat PDF combiner tool. Reorder the files if needed. Click Merge files. Sign in to download or share the merged file.


2 Answers

With Version 1.45 - December 6, 2012 is pdftk able to create bookmarks with update_info, which could be used as toc.

Its done in 3 Steps:

Precondition for my example

3 PDF files. Single page.

page1.pdf
page2.pdf
page3.pdf

1. Create the bookmark information

# build the bookmark out of an example file
pdftk page1.pdf dump_data output meta.txt
# Edit meta.txt as you need

Heres an example that worked for me, meta.txt:

InfoBegin
InfoKey: Creator
InfoValue: PDFTK
NumberOfPages: 3
PageMediaBegin
PageMediaNumber: 1
PageMediaRotation: 0
PageMediaRect: 0 0 595.32 841.92
PageMediaDimensions: 595.32 841.92
BookmarkBegin
BookmarkTitle: Page 1
BookmarkLevel: 1
BookmarkPageNumber: 1
BookmarkBegin
BookmarkTitle: Page 2
BookmarkLevel: 1
BookmarkPageNumber: 2
BookmarkBegin
BookmarkTitle: Page 3
BookmarkLevel: 1
BookmarkPageNumber: 3

2. Create an temporary merged pdf file

pdftk page* cat output temp.pdf

3. Add the bookmarks to the pdf

pdftk temp.pdf update_info meta.txt output final.pdf

When you open the final.pdf in acrobat reader you see the bookmarks on the left side. enter image description here

like image 167
jerik Avatar answered Oct 10 '22 00:10

jerik


And what's the best tool for us to merge the pdf's?

On Linux (as well as on Windows), you can install an useful little program, pdftk. It works well to bind PDF's together. For example:

$ pdftk in1.pdf in2.pdf in3.pdf in4.pdf in5.pdf in6.pdf cat output out.pdf

where in*.pdf are the input files and out.pdf is the result. In between, @jerik already gave an answer how to deal with the TOC.

like image 26
Federico A. Ramponi Avatar answered Oct 10 '22 00:10

Federico A. Ramponi