Skip to content
cetomePublic

About

Add bookmarks and clickable links to your copy of a PDF, from a small navigation file (JSON).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDFixer

Add bookmarks and clickable links to your copy of a PDF.

Some PDFs come without bookmarks, and their table of contents and cross-references ("see 7.4", "Annex B", "[5]") are plain text you cannot click. If someone has made a navigation file for that document, PDFixer puts its bookmarks and links into your own copy:

pdfixer original.pdf navigation.json

You get original_fixed.pdf next to your file, with

  • a bookmark panel that follows the structure of the document,
  • a clickable table of contents,
  • clickable references to clauses, annexes, tables, figures and the bibliography, and clickable web addresses.

Your original PDF is never changed. Works on Windows, macOS and Linux.

Navigation files for some documents are in the bookmarks folder.

Install

You need Python 3.9 or newer. Then:

python -m pip install pikepdf pypdfium2

Download pdfixer.py from this page and put it next to your PDF. That is all: there is nothing else to set up.

(On macOS and Linux the command may be python3 instead of python.)

Use

python pdfixer.py original.pdf navigation.json

The two files can be given in any order. Options:

Option What it does
-o new.pdf Name of the new PDF. Default: <your pdf>_fixed.pdf
--password PASSWORD Password of your PDF, if it has one

Example of what you see:

Added 169 bookmarks and 432 links.
Saved as: original_fixed.pdf

Install as a command (optional)

To type pdfixer from any folder instead of python pdfixer.py:

python -m pip install git+https://github.com/cetome/PDFixer

Good to know

  • You need your own copy of the PDF. A navigation file contains no text of the document: only titles of bookmarks, positions on the page, and a short fingerprint of each page. It is useless without the PDF.
  • It has to be the same document and edition. PDFixer recognises each page by its content. A copy with a few more or fewer pages at the front, or with a different header or footer line, still fits. A navigation file made for another document is refused and nothing is written.
  • Bookmarks from the navigation file replace the bookmarks your PDF has. Links are only added where your PDF has none. Nothing else is changed: the title, author and other document info of your PDF stay as they are.
  • Scanned PDFs without a text layer only work when they have exactly the same pages as the copy the navigation file was made from.

The navigation file

A plain JSON file:

{
  "format": "pdf-navigation",
  "version": 1,
  "hash": "sha256",
  "page_count": 52,
  "bookmarks": [
    {"title": "1 Scope", "level": 1, "closed": false, "page": 6, "top": 764.3}
  ],
  "links": [
    {"page": 7, "rect": [228.6, 291.9, 243.5, 304.6], "to": {"page": 11, "top": 641.8}},
    {"page": 50, "rect": [90.0, 400.1, 310.2, 412.9], "uri": "https://example.org/"}
  ],
  "pages": [
    {"size": [595.3, 841.9], "marks": [["3f2a9c01be7d", 70.9, 758.2]]}
  ]
}
  • Pages are counted from 0. Positions are in PDF points, measured from the bottom-left corner of the page.
  • bookmarks: in reading order; level 1 is the top level. top is where the page is scrolled to (leave it out to show the whole page).
  • links: rect is the clickable area; it leads to a place in the document (to) or to a web address (uri).
  • pages[].marks: for each line of text, the first 12 characters of the SHA-256 of the line (lower case, spaces collapsed) and the position of the line. They are how a page is recognised in another copy.

Licence

MIT, see LICENSE.

Libraries

PDFixer uses pikepdf (MPL-2.0) to write the PDF and pypdfium2 (Apache-2.0 / BSD-3-Clause) to read its text.

About

Add bookmarks and clickable links to your copy of a PDF, from a small navigation file (JSON).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages