I heard that bookmarks of a pdf file are stored in plain text somewhere in the file. I was wondering if it is possible to import and export bookmarks of a pdf file into and from a text file, for batch processing?

If yes, is there any description on the syntax for editing the text file containing bookmarks of a pdf file?

I was hoping for free software solutions for Ubuntu 10.10 and for Windows 7.

9 Answers 9


There's quite a variety of tools that can extract bookmarks from a pdf to a plain text file, and vice versa. Some of which are as follows:

Also, I have a script that can convert between the formats of many of these tools : bmconverter.py.

Another very nice way is to add bookmarks to a pdf via pdflatex.


You can use pdftk for this. More info: How to Export and Import PDF Bookmarks.

Export PDF bookmarks on the command-line like this:

pdftk C:\Users\Sid\Desktop\doc.pdf dump_data output C:\Users\Sid\Desktop\doc_data.txt

Import PDF bookmarks from a data file like this:

pdftk C:\Users\Sid\Desktop\doc.pdf update_info C:\Users\Sid\Desktop\doc_data.txt output C:\Users\Sid\Desktop\updated.pdf

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.

This is going to work in *nix systems if instead you are on a Windows machine. Then first install python3 and pdftk just use the booky.py file in the repo to convert bkmrks.txt to pdftk compatible format

python3 booky.py < bkmrks.txt > output.txt

and then use the export command to generate a dumped data file. Remove the previous bookmarks from that file and insert content of output.txt instead using a simple copy paste. And then import that data back.

  • In PDFtk, use dump_data_utf8 and update_info_utf8 instead of their plain variants, to be able to use UTF-8 encoding in the dump file. Otherwise you need to encode non-ASCII characters as XML numerical entities.
    – typo
    Oct 15, 2020 at 20:43

If you have a version of a document that has bookmarks and want to copy them over, a much simpler way is to use PDF-XChange Viewer (I used v2.5.211). Open the PDF that has the bookmarks (the source PDF), select all the bookmarks in the bookmarks pane, copy them using Ctrl+C, open the PDF that doesn't have the bookmarks (the target PDF), and paste them (Ctrl+V) in that PDF's bookmarks pane. PDF-Xchange Viewer preserves bookmark properties as they were from the source PDF (including any bold / italic formatting on the bookmark text). If for some reason some of the sections of the target PDF are lower or higher due to revisions made to the document, you can click the bookmark needing correction, scroll to where on the page you'd like the bookmark to open to, right-click the bookmark again and click "Set Destination". Repeat this last part as needed for any offending bookmark. Save the target PDF when finished.

This worked great for me, was quite intuitive, and I was done in a few minutes. In my particular scenario, a co-worker had produced a very long document using Word for Mac which didn't have bookmarks. Due to the length of the document, I wanted bookmarks corresponding to the document's outline. I could get Word for Windows to save the document as a PDF with bookmarks, but some formatting differences between Word for Windows and Word for Mac threw off the page count quite off (in particular, there were differences in white space around footers, and differences in the spacing between figures and the caption). I was able to play around with the headers & footers and figure sizes to get the pagination correct in Word for Windows, then saved to PDF w/ bookmarks. Unfortunately, there still were some differences in the formatting such that I wished to just apply the bookmarks to the original PDF, and that's when I figured out the solution above.

  • 2
    +1 for PDF-Xchange. The less tools the merrier
    – Ooker
    Oct 26, 2017 at 17:47

HandyOutline. 1 drag, 1 click, done. https://sourceforge.net/projects/handyoutlinerfo/. Free. Indents sub-bookmarks. Doesnt require any PDF reader/editor. Also edit, export all details to text (copy into word write a macro to tidy it into a fully functional word document) or XML, repaginate, import to PDF. Dev deserves donations.

PDF-Xchange Editor (replaced PDFViewer) randomly duplicated/missed bookmarks exported to text

JPDF required Java, exported formatting garbage, couldnt clean it to get the names only

PDFtk gave me a headache just looking at the instructions


  • Love that this one exports to XML, instead of a more idiosyncratic format. The drag and drop interface for exports couldn't be simpler also. I only wish it could do multiple at once. Apr 18, 2019 at 14:02

The specification for PDF files is available as a freely downloadable PDF from Adobe - or at least it was last time I checked. However, most PDF files have most compressible data in them compressed. There probably was a basically plaintext version of PDF once upon a time, and if so it will still be valid now, but actually getting a file in that form may be a problem.

Although I haven't done it, one very likely possibility (if you're willing to pay) is to buy Acrobat Pro, and to use the Javascript scripting abilities built into that application. To get you started...


This tutorial shows how to create bookmarks automatically using Javascript in Acrobat 7.0 Pro (the version included in Creative Suite CS2). Although that's getting a bit old, the same technique should work fine for newer versions.

Adobe applications do include a library for reading/writing text files using Javascript (something that Javascript doesn't have as standard), so it's possible to write your own import/export scripts, though non-trivial to make those scripts robust.

  • Thanks! Is there a Linux version of Acrobat Pro ?
    – Tim
    Apr 28, 2011 at 6:58
  • Sorry - I very much doubt it. AFAIK its a Mac or Windows thing, and Adobe are unlikely to support Linux unless a huge number of creative professionals (1) start using that platform, and (2) show that they're willing to pay lots for proprietary software rather than use FOSS alternatives. Seems unlikely. For a free solution, you might try a library such as blog.rubypdf.com/2007/12/12/… (for Ruby). I know even less about this - I just found it on Google.
    – user31438
    Apr 28, 2011 at 7:10

To export bookmarks, I follow a different approach that requires the use of Microsoft OneNote:

I open the PDF reader (I use the free version of Foxit) with the bookmark structure visible and then, in OneNote, I ask to take a snapshot, and select the Foxit bookmark structure.

Back to OneNote, I select the "Copy text from image" option (in the menu that appears after right-clicking the snapshot image), and I paste it on the side, to correct the indentation (usually with bullets).


I found another rather "stupid" solution to copy all of the bookmarks in a PDF as a text for use elsewhere. In Acrobat Pro (for Mac OS) there is no way to select all the bookmarks and copy/paste them in a Wordprocessor. You can however export the whole PDF as an HTML-file with the option "one single HTML-page + add navigationframe based on bookmarks". Then open the HTML in a browser, select all text in the navigationframe and copy/paste it to a Wordprocessor...


To read all bookmarks from a PDF to a text file, you can use this command with pdftk:

pdftk input.pdf dump_data output output.txt

I then used regex on Notepad++ to remove the extra parts. The following I replaced by an empty string (in order), and then I ended up with a list of bookmarks (don't forget to replace using regex in your text editor):


If you want to remove the numbers, replace this expression:

BookmarkTitle: A8.\d.\d+\s

A simple remedy:- Copy source PDF (with bookmarks) to another location, then delete all pages except Page#1, save the file. Now copy of the source file is having only one page, but with whole book marks. Rename the file to 'BOOK-MARK'. Open the target PDF, insert 'BOOK-MARK' file as first page, Save the target PDF. Open the target PDF delete the first page, now you have target file with whole book marks copied from the source PDF. You may now link the book marks to respective pages of target file. CHEERS***

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.