“It is a riddle wrapped in a mystery inside an enigma but perhaps there is a key. The key is how you get the PDF into the container field, and which platform and FM version you use to accomplish this.”
Winston Churchill, BBC radio address, 1939
(Just kidding about the second sentence.)
If you work with digital images, you’ve probably noticed the trend towards using PDFs as an image file format. I doubt many of use could have foreseen this happening when the PDF format was introduced in 1993, but in many organizations PDF has become the standard file format for images.
The good news is that the GetThumbnail function now works with PDFs in container fields in FileMaker 14, and in this article I’m going to suggest a couple reasons why you might find this useful, and explore some nuances between how PDFs in container fields behave on the Mac vs. on the PC.
Today’s demo file, pdf thumbnails, is a 45Mb download, consisting of 32 PDF images (average size 160K, average dimensions 1160×880) as well as six stored PNG thumbnails of varying dimensions for each PDF.
Before we go any further, let’s introduce a couple of terms:
- Passive thumbnail = the image that FileMaker automatically displays in a container field (under specific circumstances) to represent the binary data stored therein
- Active thumbnail = an image with maximum dimensions specified that the developer proactively generates via the GetThumbnail function
We’ll have more to say about both types of thumbnails below, but the crux of the matter is that GetThumbnail requires a passive thumbnail to create an active one. Without the former to use as a source, GetThumbnail cannot generate the latter.
Also note that in this demo all container fields have been optimized for image display, like so.
Seeing Is Believing
I promised a moment ago to offer two reasons why you might care about this; here’s the first reason…
- Start with the demo file closed (we don’t want caching to skew the results).
- Open the demo.
- Click the Active Thumbnails button, and note that a new window opens and displays almost instantaneously.
- Return to the main demo window, click Passive Thumbnails, and note that this window takes longer to display — a tiny bit longer if you’re working locally, but noticeably longer if you’re accessing the file via LAN or WAN.
So reason #1 is speed. And depending on your hosting setup, connection speed, thumbnail size and number of records in your found set, the difference between the two approaches can be dramatic.
To see the second reason…
- Click the Active Thumbnails button, and then click “Save As PDF” in the tool bar at the top of the window, and name the file “active thumbnails.pdf”.
- Next go back to the main window of the demo, click Passive Thumbnails, do a “Save As PDF” and this time name the file “passive thumbnails.pdf”
- Now compare the file sizes.
More About The Demo
As you have probably surmised, the difference in performance and output file size is determined by whether we render the original container (i.e., a passive thumbnail scaled down to 100×100), or the correspondingly sized active thumbnail.
The two layouts are identical except for the choice of field.
The storage table consists of these fields…
…with PDFs stored in the “container” field. And all the “thumb” fields are defined to use this auto-enter calc:
Note that the syntax is identical for all six “thumb” fields, and that the number at the end of the field name determines the dimensions. Of course I could have instead simply defined the AE calc for each “thumb” field individually, e.g.,
GetThumbnail ( container ; 300 ; 300 )
GetThumbnail ( container ; 200 ; 200 )
GetThumbnail ( container ; 100 ; 100 )
Why Not Use Unstored Calcs?
Why not use unstored calculation fields instead of auto-enter calcs populating standard container fields? If your primary concern is output document file size that would be fine. But if you are displaying thumbnails on-screen, and especially if you are displaying a lot of them at once in a hosted environment, your screens will render faster using the method in this demo. Also, if you use unstored calcs, the “thumb” fields will not render in FM 13.
So What Changed in FM 14?
The GetThumbnail function did not work with PDFs in container fields in FM 13, but it does in FM 14. Actually it worked in 12, was deprecated in 13 and reinstated in 14.
Does GetThumbnail work with PDFs on both Mac and PC?
Short answer: yes, as long as you have a valid passive thumbnail to use as a starting point (except, as I just mentioned, it does not work in FM 13).
Longer and more helpful answer: to the best of my knowledge it is not possible to generate the prerequisite passive thumbnail on the Windows platform so from a practical standpoint, you are much more likely use GetThumbnail to generate PDF thumbnails on the Macintosh than on the PC.
However, if you use a Macintosh to initially create passive PDF thumbnails, then there’s nothing stopping you from using GetThumbnail on a PC to generate the active equivalents (again, provided you are in FM 12 or FM 14).
For example, having previously populated this demo via the Macintosh, I’ve now opened it in FM 14 for Windows, created a new record, and begun the process of dragging and dropping from the container in the above row to the container in the new record.
Now I’ve released the mouse button and committed the record, and not only has the PDF been copied into the new record (along with its passive thumbnail), but the GetThumbnail function has performed its magic as well.
How Do You Generate A Passive Thumbnail?
In FM 12 or FM 14 for Macintosh, insert the PDFs into the “container” field via…
- Insert picture
- Import folder (that’s how I got the 32 PDFs into the demo)
- Drag and drop into the container
- Copy and paste the file into the container
- Insert PDF (this option is only available if your container is optimized for interactive content, i.e…)
Note that Insert File is specifically excluded from the above set of choices. All that gets you is an icon like the one shown in the next section, except in FM 14 for Macintosh if you script the operation, you can choose “Display: Content of file (when possible)” and it actually will work on the Mac (but not on Windows).
What Happens When You Try On A PC?
On the PC in FM 14, using any of the above methods, you end up with the icon for the file, rather than the passive thumbnail.
If you then open the file on the Mac in FM 14, at first it appears the operation was a success…
…but note that GetThumbnail has not worked (all the thumbnails are the same size—in fact, rather than images, the thumb fields contain identical copies of the source PDF). And while the image in the container field certainly looks like a passive thumbnail, it does not behave like one… e.g., you cannot copy and paste (or drag and drop) it into the container field in a new record and end up with valid active thumbnails.
What Happens When GetThumbnail Doesn’t Work?
In the above example we’re primarily talking about the inability to generate a valid passive thumbnail on the Windows platform. But what happens if we insert a PDF into the container field on a Mac in FileMaker 13?
The passive thumbnail has been created but the active thumbnails have not. If we then open the file in FileMaker 14 we see the same thing (because the botched thumbnails are stored)…
…but if in FM 14 we duplicate the record, or cut/paste the container back onto itself, then the active thumbnails will properly generate.
Incidentally, if you’re wondering about the image — it’s my cat Rascal doing yoga. We call this pose “purrfection”. (Isn’t he adorable? Eighteen pounds of furry feline splendor.)
I would love to be wrong about my contention that it is not possible to generate a passive PDF thumbnail in FileMaker for Windows, but so far my attempts at tricking FileMaker into doing so have been unsuccessful, including various experiments with the Base64Encode and Base64Decode functions. If you know of or discover a way to do this on the Windows platform, I’d appreciate you letting me know.