5

I have a PDF file. I need the bookmarks in that file extracted to a text file or an excel. I also need to validate the bookmarks from the large PDF file. How could I do that?

2

You can use the CLI of jpdftweak to extract bookmarks in CSV format:

java -jar -Xmx512M jpdftweak.jar "file.pdf" -savebookmarks "bmarks.csv" /dev/null

After validating and possibly modifying the bookmark data you could load it back into the PDF file with the following command:

java -jar -Xmx512M jpdftweak.jar "file.pdf" -loadbookmarks "bmarks.csv" "file_updated.pdf"

The -Xmx512M Java parameter is optional but can help with processing larger PDF files that require more memory.

You might want to read this related Q&A as well.

2

You can use pdftk to extract data (in particular, bookmarks) from PDF files.

Example: with pdftk 2.02,

pdftk file.pdf dump_data_utf8 | grep '^Bookmark'

outputs the list of bookmarks, 4 lines for each bookmark, under the form:

BookmarkBegin
BookmarkTitle: <title in UTF8>
BookmarkLevel: <number>
BookmarkPageNumber: <number>

where for instance, level 1 corresponds to sections, level 2 to subsections, and so on. Instead of dump_data_utf8, you can use dump_data, which will give you HTML/XML numeric entities for non-ASCII characters (e.g. &#232; for "è").

Note: Without the grep, you can get other interesting data, such as the metadata (creation date, author, keywords, title, etc.), the number of pages and the dimensions of each page. This pdftk utility can do other things on the PDF file(s); see its man page for a full description.

  • but how? That's not a very good answer, back to google :/ – MightyPork May 6 '17 at 7:46
  • @MightyPork I've added an example and other information. – vinc17 May 7 '17 at 13:24

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.