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

后端 未结 5 497
醉话见心
醉话见心 2020-12-06 07:33

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 Co

5条回答
  •  一个人的身影
    2020-12-06 08:19

    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.

提交回复
热议问题