Level: Intermediate, Version: FM 13 or later

PDF with Embedded Links

Author’s note: I’d like to offer a big thank you to Christian Schmitz of Monkeybread Software, not only for creating and continually improving a fantastic plug-in, but also for promptly and patiently answering my many questions.

A few weeks ago we looked at creating a table of contents for a PDF containing nine individual reports. The article ended by asking a somewhat rhetorical question…

Now that we have a table of contents for our master report, wouldn’t it be nice if we could hyperlink each TOC entry to its corresponding report within the PDF?

2017-02-10_180551

FileMaker doesn’t provide a built-in way to accomplish this, but it can be done using a combination of the MonkeyBread plug-in + DynaPDF Lite, and this will be explored in my next article.

…and today we’re going to dig into the nuts and bolts of what it takes to make this happen.

As usual, we have a demo file (Embedded PDF Links), but since it will only work for developers having licensed copies of the above-mentioned products, here is a PDF showing the end result: Report with Hyperlinked TOC.pdf

As before, we’re going to concentrate on this particular script…

2017-02-19_135648

…which hasn’t changed since last time except for the addition of these steps:

2017-02-20_235230

And now is probably a good time to mention that every MBS function has its own documentation page (see overview here) and the same holds true for DynaPDF functions.

We’ll take a closer look some of these steps in just a minute. First, though, I want to say a little bit about PDF page linking… how it works in general, and the particular approach I’m taking here.

A PDF page link is created by specifying a set of rectangular coordinates, and, in effect,  “drawing” an invisible rectangle at a certain location on a given page of a PDF, and then specifying the target page to go to (within that same PDF) when that link is clicked. In today’s article and demo this is accomplished via a function called “DynaPDF.PageLink“.

As chance would have it, a table of contents is ideally suited to this approach, because the entries are predictably located on the T.O.C. page, making it easy to programmatically determine where to place the invisible page link rectangles.

The layout dimensions can help us determine the width and height of the rectangle, as well as the starting position (top, left).

2017-02-21_011859

Based on the above we’re going to use these coordinates for width, height, left and top.

2017-02-21_015140

The first three will remain constant, but $T (top) will be incremented by $H (the rectangle height, i.e., 15) for each TOC entry, as the script works its way down the page drawing invisible page link rectangles.

As mentioned last time, the PDF will contain either eight or nine reports, so the TOC will have either eight or nine entries (and corresponding page values, which we will use as the target for our page links)… and, conveniently, our script has already loaded these values into variables, as part of the basic TOC generation process, as per these two highlighted steps.

2017-02-21_085841

Once the above portion of the script has completed, $totalEntries and the repeating variable, $col_2, will contain something like this.

2017-02-21_091937

Okay, let’s take a closer look at some of the page link script steps.

2017-02-21_205222

Step 63 transforms the “Save As PDF”-friendly path + filename in $$fileSpec, e.g.,

file:/C:/Users/Kevin/Desktop/report.pdf   (Windows)
file:/MacHD/Users/Kevin/Desktop/report.pdf  (Macintosh)

…into one that DynaPDF can use, e.g.,

C:\Users\Kevin\Desktop\report.pdf   (Windows)
/Users/Kevin/Desktop/report.pdf   (Macintosh)

The $counter variable initialized in step 65 will be used in step 80 to help extract page number values from the $col_2[repetitions] discussed above.

2017-02-21_113756

Step 71 begins the DynaPDF process, and as per the “DynaPDF.New” help page, there should only be one instance of this running in memory at a time (see step 90 note below).

Step 72 tells DynaPDF to begin coordinates at the top left of the page (instead of using the native PDF coordinate system, which starts at the bottom left)…

2017-02-21_141509

…and step 73 determines what the user will see when they click on a PDF link (roughly equivalent to the button “pressed” state in FileMaker), e.g.,

2017-02-21_211353

Step 79 ensures that the rectangle is invisible, i.e., does not display a border, if the user opens the PDF in Acrobat or Acrobat Reader. (The rectangle is always invisible in Preview.)

Step 80 draws the page link rectangles and assigns the target page numbers.

2017-02-21_144345

Step 87 is necessary on the Windows OS, but not on the Mac.

Step 90 frees up memory claimed by “DynaPDF.New” in step 71, and is not optional.

2017-02-21_150052

And now you know everything I know (as of Feb 2017, at any rate) about generating embedded PDF page links.


Postscript: MBS + DynaPDF Installation and Registration

On the Macintosh, I’ve chosen to install the DynaPDF library file in the FileMaker Extensions folder, along with the MBS plug-in.

2017-02-20_11-44-52

On Windows, DynaPDF consists of these two files, and again, I’ve chosen to install them in the FileMaker Extensions folder along with the MBS plug-in.

2017-02-20_113745

The startup script in the demo file calls this script (obviously, you will need to substitute the xxxxxxxxxx-es with your registration info — and note that there are four versions of DynaPDF, and the methodology we’re looking at today requires at least the “Lite” version).

2017-02-20_16-36-43

And, after running the “register” script, the Data Viewer confirms that all is well.

2017-02-19_135924

2 thoughts on “PDF with Embedded Links”

    1. I suggest submitting a detailed explanation of the problem to Christian at MBS. He’s generally very responsive when it comes to tech-support questions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.