Add and edit bookmarks to pdf












21















By getting metadata from some pdf files with bookmarks by pdftk, I observe the format of bookmarks in pdf metadata. So I am guessing that with pdftk, it is possible to add and edit bookmarks of a pdf file.



Here are three steps that I follow:




  1. I firstly get the metadata (including bookmarks if any) from a pdf
    file into a text file by pdftk in.pdf dump_data > in.info.


  2. Next I add some bookmarks into the metadata text file in.info, changing it
    from



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


    to



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    BookmarkBegin
    BookmarkTitle: Front cover
    BookmarkLevel: 1
    BookmarkPageNumber: 1
    BookmarkBegin
    BookmarkTitle: About the Author
    BookmarkLevel: 1
    BookmarkPageNumber: 5
    BookmarkBegin
    BookmarkTitle: Title page
    BookmarkLevel: 1
    BookmarkPageNumber: 6
    BookmarkBegin
    BookmarkTitle: Copyright page
    BookmarkLevel: 1
    BookmarkPageNumber: 7
    BookmarkBegin
    BookmarkTitle: Foreword
    BookmarkLevel: 1
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


  3. Then I try to put the edited metadata back to the pdf file by pdftk
    in.pdf update_info in.info output out.pdf
    .


But when I open the new pdf file out.pdf in evince or adobe reader, there is no bookmark in the new pdf file.



If I get the metadata from the new pdf file out.pdf by pdftk out.pdf dump_data > out.info, there will be no bookmarks in out.info. It looks like the bookmarks were not added successfully.



I was wondering if there are some mistakes? How shall I add and edit bookmarks of a pdf file, not necessarily by pdftk?










share|improve this question

























  • This small graphical tool worked for me. (PDF Mod 0.9.1) apps.fedoraproject.org/packages/pdfmod

    – abhijit
    Jul 28 '15 at 12:30
















21















By getting metadata from some pdf files with bookmarks by pdftk, I observe the format of bookmarks in pdf metadata. So I am guessing that with pdftk, it is possible to add and edit bookmarks of a pdf file.



Here are three steps that I follow:




  1. I firstly get the metadata (including bookmarks if any) from a pdf
    file into a text file by pdftk in.pdf dump_data > in.info.


  2. Next I add some bookmarks into the metadata text file in.info, changing it
    from



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


    to



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    BookmarkBegin
    BookmarkTitle: Front cover
    BookmarkLevel: 1
    BookmarkPageNumber: 1
    BookmarkBegin
    BookmarkTitle: About the Author
    BookmarkLevel: 1
    BookmarkPageNumber: 5
    BookmarkBegin
    BookmarkTitle: Title page
    BookmarkLevel: 1
    BookmarkPageNumber: 6
    BookmarkBegin
    BookmarkTitle: Copyright page
    BookmarkLevel: 1
    BookmarkPageNumber: 7
    BookmarkBegin
    BookmarkTitle: Foreword
    BookmarkLevel: 1
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


  3. Then I try to put the edited metadata back to the pdf file by pdftk
    in.pdf update_info in.info output out.pdf
    .


But when I open the new pdf file out.pdf in evince or adobe reader, there is no bookmark in the new pdf file.



If I get the metadata from the new pdf file out.pdf by pdftk out.pdf dump_data > out.info, there will be no bookmarks in out.info. It looks like the bookmarks were not added successfully.



I was wondering if there are some mistakes? How shall I add and edit bookmarks of a pdf file, not necessarily by pdftk?










share|improve this question

























  • This small graphical tool worked for me. (PDF Mod 0.9.1) apps.fedoraproject.org/packages/pdfmod

    – abhijit
    Jul 28 '15 at 12:30














21












21








21


19






By getting metadata from some pdf files with bookmarks by pdftk, I observe the format of bookmarks in pdf metadata. So I am guessing that with pdftk, it is possible to add and edit bookmarks of a pdf file.



Here are three steps that I follow:




  1. I firstly get the metadata (including bookmarks if any) from a pdf
    file into a text file by pdftk in.pdf dump_data > in.info.


  2. Next I add some bookmarks into the metadata text file in.info, changing it
    from



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


    to



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    BookmarkBegin
    BookmarkTitle: Front cover
    BookmarkLevel: 1
    BookmarkPageNumber: 1
    BookmarkBegin
    BookmarkTitle: About the Author
    BookmarkLevel: 1
    BookmarkPageNumber: 5
    BookmarkBegin
    BookmarkTitle: Title page
    BookmarkLevel: 1
    BookmarkPageNumber: 6
    BookmarkBegin
    BookmarkTitle: Copyright page
    BookmarkLevel: 1
    BookmarkPageNumber: 7
    BookmarkBegin
    BookmarkTitle: Foreword
    BookmarkLevel: 1
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


  3. Then I try to put the edited metadata back to the pdf file by pdftk
    in.pdf update_info in.info output out.pdf
    .


But when I open the new pdf file out.pdf in evince or adobe reader, there is no bookmark in the new pdf file.



If I get the metadata from the new pdf file out.pdf by pdftk out.pdf dump_data > out.info, there will be no bookmarks in out.info. It looks like the bookmarks were not added successfully.



I was wondering if there are some mistakes? How shall I add and edit bookmarks of a pdf file, not necessarily by pdftk?










share|improve this question
















By getting metadata from some pdf files with bookmarks by pdftk, I observe the format of bookmarks in pdf metadata. So I am guessing that with pdftk, it is possible to add and edit bookmarks of a pdf file.



Here are three steps that I follow:




  1. I firstly get the metadata (including bookmarks if any) from a pdf
    file into a text file by pdftk in.pdf dump_data > in.info.


  2. Next I add some bookmarks into the metadata text file in.info, changing it
    from



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


    to



    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    BookmarkBegin
    BookmarkTitle: Front cover
    BookmarkLevel: 1
    BookmarkPageNumber: 1
    BookmarkBegin
    BookmarkTitle: About the Author
    BookmarkLevel: 1
    BookmarkPageNumber: 5
    BookmarkBegin
    BookmarkTitle: Title page
    BookmarkLevel: 1
    BookmarkPageNumber: 6
    BookmarkBegin
    BookmarkTitle: Copyright page
    BookmarkLevel: 1
    BookmarkPageNumber: 7
    BookmarkBegin
    BookmarkTitle: Foreword
    BookmarkLevel: 1
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals


  3. Then I try to put the edited metadata back to the pdf file by pdftk
    in.pdf update_info in.info output out.pdf
    .


But when I open the new pdf file out.pdf in evince or adobe reader, there is no bookmark in the new pdf file.



If I get the metadata from the new pdf file out.pdf by pdftk out.pdf dump_data > out.info, there will be no bookmarks in out.info. It looks like the bookmarks were not added successfully.



I was wondering if there are some mistakes? How shall I add and edit bookmarks of a pdf file, not necessarily by pdftk?







pdf pdftk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '16 at 8:25









ice

32




32










asked Jul 20 '11 at 17:26









TimTim

26.5k77253464




26.5k77253464













  • This small graphical tool worked for me. (PDF Mod 0.9.1) apps.fedoraproject.org/packages/pdfmod

    – abhijit
    Jul 28 '15 at 12:30



















  • This small graphical tool worked for me. (PDF Mod 0.9.1) apps.fedoraproject.org/packages/pdfmod

    – abhijit
    Jul 28 '15 at 12:30

















This small graphical tool worked for me. (PDF Mod 0.9.1) apps.fedoraproject.org/packages/pdfmod

– abhijit
Jul 28 '15 at 12:30





This small graphical tool worked for me. (PDF Mod 0.9.1) apps.fedoraproject.org/packages/pdfmod

– abhijit
Jul 28 '15 at 12:30










9 Answers
9






active

oldest

votes


















12














It looks to me like from version 1.45 (2012-12-06), pdftk does allow modification of bookmarks via the update_info command:




You can now add or change a PDF’s bookmarks using update_info.




via:
http://www.pdflabs.com/docs/pdftk-version-history/






share|improve this answer



















  • 3





    This worked very good for me. One should add that in the input file above the BookmarkBegin tags before each bookmark entry are missing.

    – danielp
    Jul 21 '14 at 20:01





















4














jPDFtweak (Java, so runs on Unix/Linux) can alter bookmarks, but I don't know if you can script anything with it.



For scripting, I'd guess your only native Unix/Linux option would be pdflatex with the pdfpages package. But that's a learning curve if you're not already a LaTeX user.



EDIT: Actually it may be possible with ghostscript: See here or here or
here






share|improve this answer

































    4














    If you still stick with those unix scripts, then




    1. extract bookmark data dumped from pdftk

    2. write one extra script to convert dumped bookmark data to pdfmarks format, which ghostscript command gs is accepted.

    3. use gs script to merge them together with pdfmarks


    Take a look at http://blog.tremily.us/posts/PDF_bookmarks_with_Ghostscript/ the script pdf-merge.py do exactly what you (or I) want.



    pdf-merge.py --output=merged.pdf input1.pdf input2.pdf



    Some minor improvements could be done in his script




    1. unicode handling

    2. output bookmark files, so people can adjust it as well


    Anyway, it should work






    share|improve this answer


























    • One upvote! Thanks! I am looking forward to your script!

      – Tim
      Feb 7 '12 at 3:14











    • Seems the link is not working. Can you fix it please?

      – Fish Monitor
      Jul 22 '13 at 6:42





















    3














    pdftk is definetly the right tool (with the right syntax):



    BookmarkBegin
    BookmarkTitle: Chapter 1
    BookmarkLevel: 1
    BookmarkPageNumber: 1
    BookmarkBegin
    BookmarkTitle: Paragraph 1.1
    BookmarkLevel: 2
    BookmarkPageNumber: 1





    share|improve this answer































      2














      Caleb,



      As far as I understand, bookmarks as per the PDF spec can't be injected via a diagnostic tool like pdftk. Updating the metadata to refer to chapters and bookmark landing anchors that don't exist will definitely not work, it may even make your PDF inconsistent or unopenable.



      I ended up using java+iText libraries to do what you're suggesting as per this tutorial, but we're dealing with hundreds of pdfs daily, so it needed to be automated. If you're doing a one-off, Adobe Acrobat should be able to do this.






      share|improve this answer































        2














        To summarise all this good answers:



        There is bmconverter project on GitHub that can convert various PDF bookmark formats. It can convert pdftk output to jpdftweak format, although if you will use jpdftweak then you wont need to convert pdftk output to csv, as you can do all work from within jpdftweak.



        Unfortunately pdfmarks is not supported by the project, but fortunately someone posted script in bmconverter issues that can convert pdftk output to pdfmarks. So ghostscript batch option is an option






        share|improve this answer































          2














          pdftk bookmark format is a little bit tedious to write. Instead I created my own script using bash, sed, pdftk and python3. Check it out at this repo: https://github.com/SiddharthPant/booky



          So now I can create a text file(bkmrks.txt) like this which takes just 5 minutes to write even for a 1000 page pdf.



          {
          Title1, 1
          Title2, 2
          {
          Subtitle1, 3
          Subtitle2, 4
          {
          SubSubtitle1, 5
          ...
          }
          }
          }


          and then use my script



          ./booky.sh pdf_file.pdf bkmrks.txt


          this automatically creates a pdf(pdf_file_new.pdf) that has my bookmarks in it.






          share|improve this answer































            1














            Just add BookmarkBegin before each bookmark entry, as in



            BookmarkBegin
            BookmarkTitle: Front cover
            BookmarkLevel: 1
            BookmarkPageNumber: 1
            BookmarkBegin






            share|improve this answer

































              0














              The redirect that you used in step 1 will cause update_info to not work correctly. You need to specify the output file to pdftk instead:



              pdftk in.pdf dump_data output in.info


              See this answer from similar question: https://stackoverflow.com/a/30308964/3158933



              Files that I created using a redirect have a slightly larger file size and cause pdftk to issue a "Warning: unexpected case 1 in LoadDataFile(); continuing" message when running the update_info command.






              share|improve this answer








              New contributor




              cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "106"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17065%2fadd-and-edit-bookmarks-to-pdf%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                9 Answers
                9






                active

                oldest

                votes








                9 Answers
                9






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                12














                It looks to me like from version 1.45 (2012-12-06), pdftk does allow modification of bookmarks via the update_info command:




                You can now add or change a PDF’s bookmarks using update_info.




                via:
                http://www.pdflabs.com/docs/pdftk-version-history/






                share|improve this answer



















                • 3





                  This worked very good for me. One should add that in the input file above the BookmarkBegin tags before each bookmark entry are missing.

                  – danielp
                  Jul 21 '14 at 20:01


















                12














                It looks to me like from version 1.45 (2012-12-06), pdftk does allow modification of bookmarks via the update_info command:




                You can now add or change a PDF’s bookmarks using update_info.




                via:
                http://www.pdflabs.com/docs/pdftk-version-history/






                share|improve this answer



















                • 3





                  This worked very good for me. One should add that in the input file above the BookmarkBegin tags before each bookmark entry are missing.

                  – danielp
                  Jul 21 '14 at 20:01
















                12












                12








                12







                It looks to me like from version 1.45 (2012-12-06), pdftk does allow modification of bookmarks via the update_info command:




                You can now add or change a PDF’s bookmarks using update_info.




                via:
                http://www.pdflabs.com/docs/pdftk-version-history/






                share|improve this answer













                It looks to me like from version 1.45 (2012-12-06), pdftk does allow modification of bookmarks via the update_info command:




                You can now add or change a PDF’s bookmarks using update_info.




                via:
                http://www.pdflabs.com/docs/pdftk-version-history/







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 15 '13 at 3:58









                user37186user37186

                13612




                13612








                • 3





                  This worked very good for me. One should add that in the input file above the BookmarkBegin tags before each bookmark entry are missing.

                  – danielp
                  Jul 21 '14 at 20:01
















                • 3





                  This worked very good for me. One should add that in the input file above the BookmarkBegin tags before each bookmark entry are missing.

                  – danielp
                  Jul 21 '14 at 20:01










                3




                3





                This worked very good for me. One should add that in the input file above the BookmarkBegin tags before each bookmark entry are missing.

                – danielp
                Jul 21 '14 at 20:01







                This worked very good for me. One should add that in the input file above the BookmarkBegin tags before each bookmark entry are missing.

                – danielp
                Jul 21 '14 at 20:01















                4














                jPDFtweak (Java, so runs on Unix/Linux) can alter bookmarks, but I don't know if you can script anything with it.



                For scripting, I'd guess your only native Unix/Linux option would be pdflatex with the pdfpages package. But that's a learning curve if you're not already a LaTeX user.



                EDIT: Actually it may be possible with ghostscript: See here or here or
                here






                share|improve this answer






























                  4














                  jPDFtweak (Java, so runs on Unix/Linux) can alter bookmarks, but I don't know if you can script anything with it.



                  For scripting, I'd guess your only native Unix/Linux option would be pdflatex with the pdfpages package. But that's a learning curve if you're not already a LaTeX user.



                  EDIT: Actually it may be possible with ghostscript: See here or here or
                  here






                  share|improve this answer




























                    4












                    4








                    4







                    jPDFtweak (Java, so runs on Unix/Linux) can alter bookmarks, but I don't know if you can script anything with it.



                    For scripting, I'd guess your only native Unix/Linux option would be pdflatex with the pdfpages package. But that's a learning curve if you're not already a LaTeX user.



                    EDIT: Actually it may be possible with ghostscript: See here or here or
                    here






                    share|improve this answer















                    jPDFtweak (Java, so runs on Unix/Linux) can alter bookmarks, but I don't know if you can script anything with it.



                    For scripting, I'd guess your only native Unix/Linux option would be pdflatex with the pdfpages package. But that's a learning curve if you're not already a LaTeX user.



                    EDIT: Actually it may be possible with ghostscript: See here or here or
                    here







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 23 '17 at 12:40









                    Community

                    1




                    1










                    answered Aug 12 '11 at 0:00









                    frabjousfrabjous

                    4,3371825




                    4,3371825























                        4














                        If you still stick with those unix scripts, then




                        1. extract bookmark data dumped from pdftk

                        2. write one extra script to convert dumped bookmark data to pdfmarks format, which ghostscript command gs is accepted.

                        3. use gs script to merge them together with pdfmarks


                        Take a look at http://blog.tremily.us/posts/PDF_bookmarks_with_Ghostscript/ the script pdf-merge.py do exactly what you (or I) want.



                        pdf-merge.py --output=merged.pdf input1.pdf input2.pdf



                        Some minor improvements could be done in his script




                        1. unicode handling

                        2. output bookmark files, so people can adjust it as well


                        Anyway, it should work






                        share|improve this answer


























                        • One upvote! Thanks! I am looking forward to your script!

                          – Tim
                          Feb 7 '12 at 3:14











                        • Seems the link is not working. Can you fix it please?

                          – Fish Monitor
                          Jul 22 '13 at 6:42


















                        4














                        If you still stick with those unix scripts, then




                        1. extract bookmark data dumped from pdftk

                        2. write one extra script to convert dumped bookmark data to pdfmarks format, which ghostscript command gs is accepted.

                        3. use gs script to merge them together with pdfmarks


                        Take a look at http://blog.tremily.us/posts/PDF_bookmarks_with_Ghostscript/ the script pdf-merge.py do exactly what you (or I) want.



                        pdf-merge.py --output=merged.pdf input1.pdf input2.pdf



                        Some minor improvements could be done in his script




                        1. unicode handling

                        2. output bookmark files, so people can adjust it as well


                        Anyway, it should work






                        share|improve this answer


























                        • One upvote! Thanks! I am looking forward to your script!

                          – Tim
                          Feb 7 '12 at 3:14











                        • Seems the link is not working. Can you fix it please?

                          – Fish Monitor
                          Jul 22 '13 at 6:42
















                        4












                        4








                        4







                        If you still stick with those unix scripts, then




                        1. extract bookmark data dumped from pdftk

                        2. write one extra script to convert dumped bookmark data to pdfmarks format, which ghostscript command gs is accepted.

                        3. use gs script to merge them together with pdfmarks


                        Take a look at http://blog.tremily.us/posts/PDF_bookmarks_with_Ghostscript/ the script pdf-merge.py do exactly what you (or I) want.



                        pdf-merge.py --output=merged.pdf input1.pdf input2.pdf



                        Some minor improvements could be done in his script




                        1. unicode handling

                        2. output bookmark files, so people can adjust it as well


                        Anyway, it should work






                        share|improve this answer















                        If you still stick with those unix scripts, then




                        1. extract bookmark data dumped from pdftk

                        2. write one extra script to convert dumped bookmark data to pdfmarks format, which ghostscript command gs is accepted.

                        3. use gs script to merge them together with pdfmarks


                        Take a look at http://blog.tremily.us/posts/PDF_bookmarks_with_Ghostscript/ the script pdf-merge.py do exactly what you (or I) want.



                        pdf-merge.py --output=merged.pdf input1.pdf input2.pdf



                        Some minor improvements could be done in his script




                        1. unicode handling

                        2. output bookmark files, so people can adjust it as well


                        Anyway, it should work







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jul 30 '13 at 5:43

























                        answered Feb 7 '12 at 3:12









                        larrycailarrycai

                        2821210




                        2821210













                        • One upvote! Thanks! I am looking forward to your script!

                          – Tim
                          Feb 7 '12 at 3:14











                        • Seems the link is not working. Can you fix it please?

                          – Fish Monitor
                          Jul 22 '13 at 6:42





















                        • One upvote! Thanks! I am looking forward to your script!

                          – Tim
                          Feb 7 '12 at 3:14











                        • Seems the link is not working. Can you fix it please?

                          – Fish Monitor
                          Jul 22 '13 at 6:42



















                        One upvote! Thanks! I am looking forward to your script!

                        – Tim
                        Feb 7 '12 at 3:14





                        One upvote! Thanks! I am looking forward to your script!

                        – Tim
                        Feb 7 '12 at 3:14













                        Seems the link is not working. Can you fix it please?

                        – Fish Monitor
                        Jul 22 '13 at 6:42







                        Seems the link is not working. Can you fix it please?

                        – Fish Monitor
                        Jul 22 '13 at 6:42













                        3














                        pdftk is definetly the right tool (with the right syntax):



                        BookmarkBegin
                        BookmarkTitle: Chapter 1
                        BookmarkLevel: 1
                        BookmarkPageNumber: 1
                        BookmarkBegin
                        BookmarkTitle: Paragraph 1.1
                        BookmarkLevel: 2
                        BookmarkPageNumber: 1





                        share|improve this answer




























                          3














                          pdftk is definetly the right tool (with the right syntax):



                          BookmarkBegin
                          BookmarkTitle: Chapter 1
                          BookmarkLevel: 1
                          BookmarkPageNumber: 1
                          BookmarkBegin
                          BookmarkTitle: Paragraph 1.1
                          BookmarkLevel: 2
                          BookmarkPageNumber: 1





                          share|improve this answer


























                            3












                            3








                            3







                            pdftk is definetly the right tool (with the right syntax):



                            BookmarkBegin
                            BookmarkTitle: Chapter 1
                            BookmarkLevel: 1
                            BookmarkPageNumber: 1
                            BookmarkBegin
                            BookmarkTitle: Paragraph 1.1
                            BookmarkLevel: 2
                            BookmarkPageNumber: 1





                            share|improve this answer













                            pdftk is definetly the right tool (with the right syntax):



                            BookmarkBegin
                            BookmarkTitle: Chapter 1
                            BookmarkLevel: 1
                            BookmarkPageNumber: 1
                            BookmarkBegin
                            BookmarkTitle: Paragraph 1.1
                            BookmarkLevel: 2
                            BookmarkPageNumber: 1






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 27 '15 at 10:40









                            carlocarlo

                            311




                            311























                                2














                                Caleb,



                                As far as I understand, bookmarks as per the PDF spec can't be injected via a diagnostic tool like pdftk. Updating the metadata to refer to chapters and bookmark landing anchors that don't exist will definitely not work, it may even make your PDF inconsistent or unopenable.



                                I ended up using java+iText libraries to do what you're suggesting as per this tutorial, but we're dealing with hundreds of pdfs daily, so it needed to be automated. If you're doing a one-off, Adobe Acrobat should be able to do this.






                                share|improve this answer




























                                  2














                                  Caleb,



                                  As far as I understand, bookmarks as per the PDF spec can't be injected via a diagnostic tool like pdftk. Updating the metadata to refer to chapters and bookmark landing anchors that don't exist will definitely not work, it may even make your PDF inconsistent or unopenable.



                                  I ended up using java+iText libraries to do what you're suggesting as per this tutorial, but we're dealing with hundreds of pdfs daily, so it needed to be automated. If you're doing a one-off, Adobe Acrobat should be able to do this.






                                  share|improve this answer


























                                    2












                                    2








                                    2







                                    Caleb,



                                    As far as I understand, bookmarks as per the PDF spec can't be injected via a diagnostic tool like pdftk. Updating the metadata to refer to chapters and bookmark landing anchors that don't exist will definitely not work, it may even make your PDF inconsistent or unopenable.



                                    I ended up using java+iText libraries to do what you're suggesting as per this tutorial, but we're dealing with hundreds of pdfs daily, so it needed to be automated. If you're doing a one-off, Adobe Acrobat should be able to do this.






                                    share|improve this answer













                                    Caleb,



                                    As far as I understand, bookmarks as per the PDF spec can't be injected via a diagnostic tool like pdftk. Updating the metadata to refer to chapters and bookmark landing anchors that don't exist will definitely not work, it may even make your PDF inconsistent or unopenable.



                                    I ended up using java+iText libraries to do what you're suggesting as per this tutorial, but we're dealing with hundreds of pdfs daily, so it needed to be automated. If you're doing a one-off, Adobe Acrobat should be able to do this.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Aug 11 '11 at 23:41









                                    r00fusr00fus

                                    1212




                                    1212























                                        2














                                        To summarise all this good answers:



                                        There is bmconverter project on GitHub that can convert various PDF bookmark formats. It can convert pdftk output to jpdftweak format, although if you will use jpdftweak then you wont need to convert pdftk output to csv, as you can do all work from within jpdftweak.



                                        Unfortunately pdfmarks is not supported by the project, but fortunately someone posted script in bmconverter issues that can convert pdftk output to pdfmarks. So ghostscript batch option is an option






                                        share|improve this answer




























                                          2














                                          To summarise all this good answers:



                                          There is bmconverter project on GitHub that can convert various PDF bookmark formats. It can convert pdftk output to jpdftweak format, although if you will use jpdftweak then you wont need to convert pdftk output to csv, as you can do all work from within jpdftweak.



                                          Unfortunately pdfmarks is not supported by the project, but fortunately someone posted script in bmconverter issues that can convert pdftk output to pdfmarks. So ghostscript batch option is an option






                                          share|improve this answer


























                                            2












                                            2








                                            2







                                            To summarise all this good answers:



                                            There is bmconverter project on GitHub that can convert various PDF bookmark formats. It can convert pdftk output to jpdftweak format, although if you will use jpdftweak then you wont need to convert pdftk output to csv, as you can do all work from within jpdftweak.



                                            Unfortunately pdfmarks is not supported by the project, but fortunately someone posted script in bmconverter issues that can convert pdftk output to pdfmarks. So ghostscript batch option is an option






                                            share|improve this answer













                                            To summarise all this good answers:



                                            There is bmconverter project on GitHub that can convert various PDF bookmark formats. It can convert pdftk output to jpdftweak format, although if you will use jpdftweak then you wont need to convert pdftk output to csv, as you can do all work from within jpdftweak.



                                            Unfortunately pdfmarks is not supported by the project, but fortunately someone posted script in bmconverter issues that can convert pdftk output to pdfmarks. So ghostscript batch option is an option







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Apr 19 '12 at 9:45









                                            zetahzetah

                                            69241019




                                            69241019























                                                2














                                                pdftk bookmark format is a little bit tedious to write. Instead I created my own script using bash, sed, pdftk and python3. Check it out at this repo: https://github.com/SiddharthPant/booky



                                                So now I can create a text file(bkmrks.txt) like this which takes just 5 minutes to write even for a 1000 page pdf.



                                                {
                                                Title1, 1
                                                Title2, 2
                                                {
                                                Subtitle1, 3
                                                Subtitle2, 4
                                                {
                                                SubSubtitle1, 5
                                                ...
                                                }
                                                }
                                                }


                                                and then use my script



                                                ./booky.sh pdf_file.pdf bkmrks.txt


                                                this automatically creates a pdf(pdf_file_new.pdf) that has my bookmarks in it.






                                                share|improve this answer




























                                                  2














                                                  pdftk bookmark format is a little bit tedious to write. Instead I created my own script using bash, sed, pdftk and python3. Check it out at this repo: https://github.com/SiddharthPant/booky



                                                  So now I can create a text file(bkmrks.txt) like this which takes just 5 minutes to write even for a 1000 page pdf.



                                                  {
                                                  Title1, 1
                                                  Title2, 2
                                                  {
                                                  Subtitle1, 3
                                                  Subtitle2, 4
                                                  {
                                                  SubSubtitle1, 5
                                                  ...
                                                  }
                                                  }
                                                  }


                                                  and then use my script



                                                  ./booky.sh pdf_file.pdf bkmrks.txt


                                                  this automatically creates a pdf(pdf_file_new.pdf) that has my bookmarks in it.






                                                  share|improve this answer


























                                                    2












                                                    2








                                                    2







                                                    pdftk bookmark format is a little bit tedious to write. Instead I created my own script using bash, sed, pdftk and python3. Check it out at this repo: https://github.com/SiddharthPant/booky



                                                    So now I can create a text file(bkmrks.txt) like this which takes just 5 minutes to write even for a 1000 page pdf.



                                                    {
                                                    Title1, 1
                                                    Title2, 2
                                                    {
                                                    Subtitle1, 3
                                                    Subtitle2, 4
                                                    {
                                                    SubSubtitle1, 5
                                                    ...
                                                    }
                                                    }
                                                    }


                                                    and then use my script



                                                    ./booky.sh pdf_file.pdf bkmrks.txt


                                                    this automatically creates a pdf(pdf_file_new.pdf) that has my bookmarks in it.






                                                    share|improve this answer













                                                    pdftk bookmark format is a little bit tedious to write. Instead I created my own script using bash, sed, pdftk and python3. Check it out at this repo: https://github.com/SiddharthPant/booky



                                                    So now I can create a text file(bkmrks.txt) like this which takes just 5 minutes to write even for a 1000 page pdf.



                                                    {
                                                    Title1, 1
                                                    Title2, 2
                                                    {
                                                    Subtitle1, 3
                                                    Subtitle2, 4
                                                    {
                                                    SubSubtitle1, 5
                                                    ...
                                                    }
                                                    }
                                                    }


                                                    and then use my script



                                                    ./booky.sh pdf_file.pdf bkmrks.txt


                                                    this automatically creates a pdf(pdf_file_new.pdf) that has my bookmarks in it.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Feb 23 '16 at 12:19









                                                    Siddharth PantSiddharth Pant

                                                    711




                                                    711























                                                        1














                                                        Just add BookmarkBegin before each bookmark entry, as in



                                                        BookmarkBegin
                                                        BookmarkTitle: Front cover
                                                        BookmarkLevel: 1
                                                        BookmarkPageNumber: 1
                                                        BookmarkBegin






                                                        share|improve this answer






























                                                          1














                                                          Just add BookmarkBegin before each bookmark entry, as in



                                                          BookmarkBegin
                                                          BookmarkTitle: Front cover
                                                          BookmarkLevel: 1
                                                          BookmarkPageNumber: 1
                                                          BookmarkBegin






                                                          share|improve this answer




























                                                            1












                                                            1








                                                            1







                                                            Just add BookmarkBegin before each bookmark entry, as in



                                                            BookmarkBegin
                                                            BookmarkTitle: Front cover
                                                            BookmarkLevel: 1
                                                            BookmarkPageNumber: 1
                                                            BookmarkBegin






                                                            share|improve this answer















                                                            Just add BookmarkBegin before each bookmark entry, as in



                                                            BookmarkBegin
                                                            BookmarkTitle: Front cover
                                                            BookmarkLevel: 1
                                                            BookmarkPageNumber: 1
                                                            BookmarkBegin







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Jun 30 '15 at 1:41









                                                            G-Man

                                                            13.1k93465




                                                            13.1k93465










                                                            answered Jun 30 '15 at 0:03









                                                            tofleploftofleplof

                                                            111




                                                            111























                                                                0














                                                                The redirect that you used in step 1 will cause update_info to not work correctly. You need to specify the output file to pdftk instead:



                                                                pdftk in.pdf dump_data output in.info


                                                                See this answer from similar question: https://stackoverflow.com/a/30308964/3158933



                                                                Files that I created using a redirect have a slightly larger file size and cause pdftk to issue a "Warning: unexpected case 1 in LoadDataFile(); continuing" message when running the update_info command.






                                                                share|improve this answer








                                                                New contributor




                                                                cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                Check out our Code of Conduct.

























                                                                  0














                                                                  The redirect that you used in step 1 will cause update_info to not work correctly. You need to specify the output file to pdftk instead:



                                                                  pdftk in.pdf dump_data output in.info


                                                                  See this answer from similar question: https://stackoverflow.com/a/30308964/3158933



                                                                  Files that I created using a redirect have a slightly larger file size and cause pdftk to issue a "Warning: unexpected case 1 in LoadDataFile(); continuing" message when running the update_info command.






                                                                  share|improve this answer








                                                                  New contributor




                                                                  cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                  Check out our Code of Conduct.























                                                                    0












                                                                    0








                                                                    0







                                                                    The redirect that you used in step 1 will cause update_info to not work correctly. You need to specify the output file to pdftk instead:



                                                                    pdftk in.pdf dump_data output in.info


                                                                    See this answer from similar question: https://stackoverflow.com/a/30308964/3158933



                                                                    Files that I created using a redirect have a slightly larger file size and cause pdftk to issue a "Warning: unexpected case 1 in LoadDataFile(); continuing" message when running the update_info command.






                                                                    share|improve this answer








                                                                    New contributor




                                                                    cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.










                                                                    The redirect that you used in step 1 will cause update_info to not work correctly. You need to specify the output file to pdftk instead:



                                                                    pdftk in.pdf dump_data output in.info


                                                                    See this answer from similar question: https://stackoverflow.com/a/30308964/3158933



                                                                    Files that I created using a redirect have a slightly larger file size and cause pdftk to issue a "Warning: unexpected case 1 in LoadDataFile(); continuing" message when running the update_info command.







                                                                    share|improve this answer








                                                                    New contributor




                                                                    cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.









                                                                    share|improve this answer



                                                                    share|improve this answer






                                                                    New contributor




                                                                    cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.









                                                                    answered 10 mins ago









                                                                    cnachtmanncnachtmann

                                                                    1




                                                                    1




                                                                    New contributor




                                                                    cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.





                                                                    New contributor





                                                                    cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.






                                                                    cnachtmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                    Check out our Code of Conduct.






























                                                                        draft saved

                                                                        draft discarded




















































                                                                        Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid



                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function () {
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17065%2fadd-and-edit-bookmarks-to-pdf%23new-answer', 'question_page');
                                                                        }
                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        Popular posts from this blog

                                                                        Histoire des bourses de valeurs

                                                                        Why is there Russian traffic in my log files?

                                                                        Rename multiple files to decrement number in file name?