@Prusa - PDF Bookmarks - an easy, FOSS, way to add them to the assembly manual's metadata
Clear all

@Prusa - PDF Bookmarks - an easy, FOSS, way to add them to the assembly manual's metadata  

New Member
@Prusa - PDF Bookmarks - an easy, FOSS, way to add them to the assembly manual's metadata


First post (+ first printer, but this isn't about me).

After downloading the PDF version of the manual I noticed the lack of bookmarks/linking. If Prusa Peeps are interested, these are easy to add using the free PDF Tool Kit app aka pdftk (BSD License). It is available in Ubuntu and some other disros in the native repository. If it is not available in your distro of choice, try the options listed here: https://gitlab.com/pdftk-java/pdftk. There is a docker image available in that repo along with a couple of binary options that may work.

 Using pdftk to make bookmarks is super simple. Start with:

$ pdftk input.pdf dump_data output report.txt

This will generate a file with the metadata from the pdf. Open this file and you'll see around a dozen lines with the author, software used to create the pdf, timestamps, etc. This section ends with a line containing the number of pages. If the PDF contained bookmarks already, they begin just after the page numbers line. If the document did not contain bookmarks, the rest of the metadata contains the page display size parameters for each page.

 Creating new bookmarks involves adding four lines to this metadata file for each bookmark entry. Below is an example with the first three entries I added to the MK3S assembly manual's table of contents:

BookmarkTitle: Table of Contents
BookmarkLevel: 1
BookmarkPageNumber: 1
BookmarkTitle: 1 Introduction
BookmarkLevel: 2
BookmarkPageNumber: 7
BookmarkTitle: Step 1 - All the required tools are included
BookmarkLevel: 3
BookmarkPageNumber: 8

The first entry is BookmarkBegin. This initiates the entry. The BookmarkTitle: section is the text to display in the bookmarks menu. The BookmarkLevel:  line is nesting control. This is how a folding menu is created. In the attached PDF with bookmarks added, you will better see how this works. Once the list is complete, save the metadata text file and use the following command:

$ pdftk doc-without-bookmarks.pdf update_info edited-metadata.txt output doc-with-bookmarks.pdf

  This is a very simple tool. It can't link to actual text on a page or anything deeper than a page number. However, it adds a useful feature at almost no cost. I formatted the metadata and added bookmarks using 4 or 5 find and replace commands in a text editor after copying the text from the table of contents. As mentioned, I have attached the assembly manual with the bookmarks I added. I also attached the edited metadata text file. The original file is 24,296,948 bytes. The file with bookmarks is 24,341,128 bytes. The text file is 44,477 bytes. So this mod adds 44KB to the pdf file, just the cost of the strings text 🙂




P.S. I've added bookmarks to many pdf scans of old databooks that are posted on Archive.org. In my experience, bookmark link text needs to be concise with most information the reader will use as far to the left as possible for each bookmark title entry. No one wants to use a bookmarks menu that takes up a significant percentage of their screen when navigating. For this reason, I would move information like the "Step <number>" to the right side of each line in the bookmarks, but I did not take this artistic license in the attached version.  

Posted : 14/03/2021 3:43 am