Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create bookmarks into a PDF file via command line

I am searching for a command line tool to add bookmarks to a PDF file.

What I have is a page number and a label. Would love to create bookmark called label linking to page page number.

Does any one know a command line tool (preferably OSX) for doing this?

I have about 4000 pages PDF files and about 150 bookmarks and would love to automate it.

My plan is to use a system call within a r-script.

EDIT

I create about 4000 single PDF files with graphs and I am using the OSX system command /System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py to join the PDFs together. Previously I was using pdfjoin from pdfjam package, but this was way too slow. In the end, this is how I get my PDF where I add the bookmarks by hand with Adobe Acrobat Professional at the moment.

like image 872
drmariod Avatar asked May 18 '15 13:05

drmariod


People also ask

How to create bookmarks in PDF file?

Create Bookmarks in PDF File To set bookmarks in PDF document, you can click on the "View" button to open the left side toolbar, and then you can choose the "Bookmark" option. Right click on the space of the toolbar on the left side and click on the "Add Entry" button. Then you can create bookmark in PDF file.

How to edit bookmarks in Adobe Acrobat?

Open the PDF document you would like to edit in Adobe Acrobat and the click on "Bookmarks" in the navigation bar. Click on "New Bookmark" at the top of the panel to add a new bookmark to the panel. Step 2. Go ahead and enter the name of the bookmark and then press "Enter".

How to add a bookmark in Soda PDF?

How to Add a Bookmark in Soda PDF 1 Go to the Soda PDF official website to access the program. ... 2 Once the document is open in Soda PDF, click on the "Bookmarks" icon in the navigation panel. This will open the bookmark panel. 3 To add a bookmark to the PDF, click on "Add" on the bookmark panel. See More....

What is the use of a PDF-Bookmarker?

-Bookmarking a PDF document is very simple. -Can add security features to a PDF, including signatures and a watermark. -Can be used to create and convert PDF documents to other formats. -Can be used to create PDF forms and add data to existing PDF forms.


1 Answers

You can also use pdftk. It is also available for OS X.

I'm not going through all the details here and now, because it's been done elsewhere at great length already. Just briefly:

  1. Create a sample PDF from your original files (without bookmarks).
  2. Add some bookmarks with Adobe Acrobat (which you seem to have access to).
  3. Run one of these commands:

    pdftk my.pdf dump_data output -
    pdftk my.pdf dump_data output bookmarks+otherdata.txt
    
  4. Study the format of the output.

  5. Modify the output .txt file by adding all the entries you want.
  6. Run PDFTK again:

    pdftk my.pdf update_info bookmarks.txt output bookmarked.pdf
    

Additional Information

This is the Bookmark format I noticed after inspecting in Step 4 above.

BookmarkBegin
BookmarkTitle: -- Your Title 1 --
BookmarkLevel: 1
BookmarkPageNumber: 1
BookmarkBegin
BookmarkTitle: -- Your Title 2 --
BookmarkLevel: 1
BookmarkPageNumber: 2
BookmarkBegin
BookmarkTitle: -- Your Title 3 --
...
...
and so on...

And replace the above.. in the appropriate place.

like image 53
Kurt Pfeifle Avatar answered Sep 28 '22 10:09

Kurt Pfeifle