PDF Deep Linking: Generate URL that Opens a PDF at Specified Page Number

These macros allow one to generate links on the fly that open locally-stored PDF documents at specific page locations. A common use scenario would be inserting links into a written note or other document via typed string triggers which expand to URLs targeting specific pages of a PDF document. For example, I write a note referencing information located on a particular page of a document. Then, I insert a link targeting that exact page in the PDF document, so that later, while reviewing my notes, if I want to check that exact page in the PDF document, I just click the link and it opens the document at the specified page. If I have the document open while I am writing notes, I can easily check the referenced pages within my notes by clicking on the links.

There are two macros that make this work.

Macro #1 opens a specific PDF document in the default application to a page number specified by variable passed from the second macro.



Once the POSIX path for the PDF document entered into the "SET PDF PATH" action, the user must copy the unique UUID of the macro. The UUID is copied by clicking Edit > Copy as > Copy UUID.

Macro #2 incorporates the previous macro's unique UUID into, and pastes, a kmtrigger:// URL that, when opened, triggers Macro #1, which opens the document.

Macro # 2: GO-TO-PAGE EXPANSION TEMPLATE.kmmacros (4.4 KB)

Macro #2, as I've designed it, is triggered by a typed string trigger that programmatically starts with a string of the users choice (perhaps some mnemonic pertaining to the target PDF document) and that ends with an arbitrarily chosen page number for the target PDF document, e.g., "trigger23" or "trigger12" or whatever page number is desired. (I also always incorporate a space at the end of my string triggers.)


The page number is captured into a variable and stuck on the end of the kmtrigger:// URL as it is pasted. When the URL is opened, e.g., by being clicked, it triggers Macro #1, opening the document at the specified page.

Here's an example of how I incorporate a kmtrigger:// URL into a note:

That link will open the target PDF to page 9, where the source material for the text is located.

I like using the kmtrigger:// URL scheme over other methods (such as Skim links) because the link can be generated very quickly while typing in-line and is app agnostic. Incorporated into this macro system, it opens the PDF into whatever the default app is (among four apps specified in Macro #1). The kmtrigger:// URL is also more compact and "aesthetically pleasing" than other kinds of URLs one might find oneself inserting into text.

I have tested these macros with Preview, Skim, PDF Expert, and Acrobat, and they work consistently. Please be advised that if you insert a URL pointing to a locally-stored document into a Microsoft Word document, you may encounter irritating and seemingly inescapable warning dialogs. Plain text editors I have used, like TextEdit and The Archive, have no such issues.