Tools for PDF internal links

Named destinations can be programmed

Named destinations are the standard answer to the frequently-asked question: is it possible to hyperlink within a PDF instance, that is, to a particular page or image or text?

Not so well-known is that named destinations are programmable. That is, the usual advice only mentions Acrobat or a similar proprietary, graphical-user-interface application as a way to manage named destinations. Named destinations are documented elements of the PDF standard, though, and can be automated as easily as any other PDF aspect.

A use case

Our company writes applications which, among other things, generate hundreds of PDF reports daily. Most of these are synthesized from disparate parts: we pull together scans of paper documents, content from several databases, "sections" or "chapters" contributed by members of end-user teams playing various roles, and standard templates and images. Consider, for a moment a signature page: this needs to appear in proper sequence in the appendix of certain reports, but other pages in the body of the same report must refer to a specific signature page. When the PDF is printed, of course, the only way to do this is with an expression like, "see signature page 83 of Appendix B". On-line instances, though, can make those references "live" by expressing them as hyperlinks. While the reports we generate are private, example of the effect are the reference above to the PDF standard, or this hyperlink to the beginning of the tax table within the 2010 IRS instructions for Form 1040.

The easiest way to program such hyperlinks is to add named destinations within PDF instances as we synthesize and merge them. We use a variety of different technologies; coding can be as simple, though, as this pyPdf-based example:

    from pyPdf import PdfFileMerger
    signature_page = "signatureC.pdf"
    instance = PdfFileMerger()
    instance.addNamedDestination("signature3", 1)

When the resulting PDF report is eventually written out, the chosen signature page is available as


Coming up

We have several more tips that illustrate techniques we've seen documented nowhere else that we use to make our applications more convenient to end-users: a Web combobox, SVG widgetry, full-text searches, and networking automations. Look for them this week.

ITWorld DealPost: The best in tech deals and discounts.
Shop Tech Products at Amazon