Feature Request: Automating PDF internal page links

I’ve been quiet here but busy in real life, which I guess is a good thing (if only it paid better!).

I’ve started a new business where I review the books and records of a strata scheme (think condo association), collate those documents which might be relevant into a single PDF and add a summary and review report (about 10 pages) at the start.

These reports often end up in the hundreds of pages, and I’m wanting to make things easier for the people commissioning them to navigate around.

I’m using DEVONthink Pro to collect all the files together (usually a subset of the total download of all records), where I duplicate the originals from a “Raw Download” folder so I can rename them with a particular naming scheme I use to keep things arranged. This is the sort of thing I find DTP excels at for me.

Then I’m using DTP’s “Merge [n] Documents” command to build up my report with all the annotations after it in a reasonable facsimile of sensible order.

Nicely, DTP’s Merge keeps the filenames as bookmarks to the first page of the documents, even across multiple merges. Lovely, and thank you devs!

For things like meeting minutes, I then create new links and sub-links to organise them into so the TOC/Bookmarks list is not too long. Easy, thank you devs!

I use DTP’s link creation capacity to create links in my report to things I have “sighted and attached”, as well as in a list of the usually-attached files at the end of my report before the annexures start.

It’s not too onerous to do those manually, but the next step is a bit more onerous.

I’d like to link from all the annexure pages back to my report in the first 10 or so pages, likely the list of annexure types at the end of my report, so for any given report, the same page number.

However, while I could use the Imprinter to place some text on all pages saying “Return to page [n]”, I can’t include page links in Imprints, and I can’t copy and past the link greyed rectangle from page to page, either.

I’ve used cpdf and Keyboard Maestro in the past to annotate multiple PDFs with text from a CSV file, and I know, once I work on the JSON format, I could use cpdf to overlay page links on the “Return to page [n]” text I can imprint in DTP or cpdf, but I’d also love if the page links in DTP could be automated and/or copied.

With variable for [page the link is on], [bounding box dimensions] on that page and [page to link to] would allow for programmatic creation of new links. Similar to click and drag to set the bounding box with the link tool on a page, then navigate to a page and click Set in the Annotations window to set the Destination to that page.

I know I could control the GUI in KBM to draw the links on all pages and set the destination back to my report mage, but that seems inefficient, especially across different computers and window sizes, positions, and zoom.

I know cpdf will be able to do it, but generating the JSON for that is more convoluted than doing it internally in DTP could potentially be.

I’m not keen on an Acrobat subscription if that can do it, and/or another PDF view/editor app.

I hope that all makes sense, would be interested in the devs’ thoughts (or if I’m missing something obvious).

Sean

Noted but no promises. A scriptable third-party PDF editor might be an alternative in the meantime.

1 Like

Appreciate the consideration.

Trying to keep things as light as possible as far as installed apps, so I’ll probably use KBM to (clumsily) control the UI.

I’m not going to bother using cpdf – to add annotations, I need to do a heap of PostScript in JSON :confused:

I’ll keep my fingers crossed on the DTP front :crossed_fingers:t2: :folded_hands:t2:

Sean

PyMuPDF can do this easily. Claude Cowork can install it for you and then can process your PDFs via the Devonthink MCP Server.

2 Likes

Thank you, I’ll have a look at that.

I’m a #NoAI guy, so I’ll enjoy exploring :slight_smile:

Sean

1 Like

Proof of concept done, so thanks for this – I’d still like to do it via AppleScript within DTP (as I think that’s a worthwhile addition), but this is the best currently available solution for me so far :slight_smile:

Sean

I now have a more developed PyMuPDF proof of concept which:

  • Places a Back button .svg at the same relative tocation on all pages after my report
  • Creates a link back to the last page of my report the same size as the Back button
  • Creates a small transparent watermark at the bottom of all pages (similar to an Imprint) – I may or may not keep this element, but I learnt a lot implementing it

Next step is tidying the code and accommodating arguments so I can specify the last page number of my report, include the DTP4 item link in the watermark, etc.

Incremental saves in PyMuPDF are the only way to save back to the original document, but the filesize is ~10% larger than creating a new output file (a difference of about 5MB on the test file I’ve been using, which is a “real” report I’ve done, so indicative for a 300+ pages file).

Because I want to have my original DTP4 item’s link in the watermark (so I can see which report the original page/s came from if they’ve been extracted for other people’s use in their own reports for other apartments in the building), I need to save to the original DTP4 item, not create a new file with a new UUID (and thereore item link when placed in DTP4).

Thanks again to @rkaplan for the PyMuPDF pointer, it may obviate the need for programmatic control over links within DTP4, but I still think it’d be more elegant :slight_smile:

Sean

1 Like

You are quite welcome.

FYI for those who may be interested - I discovered PyMuPDF while testing a beta version of an MCP server to the Bookends reference manager. The combination of the Bookendsd MCP, Devonthink MCP, and PyMuPDF is tremendously useful. I used PyMuPDF to create automated PDF highlights of key content in academic journals.

1 Like