Level: Intermediate, Version: FM 12 or later

PDF Catalog with Table of Contents

Recently I was asked by a client whether we could produce a PDF catalog from his company’s database, with products grouped by manufacturer. Me: “Of course, this is FileMaker.” Him: “Can it have a table of contents?” Me: “Yeah, sure, no problem.”

Actually, it took some trial and error, but we got there eventually…

7-13-2013 4-36-23 PM

…and we’re going to look at a simplified version with sample data in today’s demo file: pdf-catalog-with-toc

7-13-2013 10-37-43 AM-600

In addition to producing a table of contents, we need to…

  1. Assemble multiple separate “print jobs” into a single PDF
    (front cover, TOC, product listing, back cover)
  2. Make sure FileMaker page numbers are consistent with PDF page numbers
    (if the front cover + TOC take up 4 pages, then “page one” of the product listing will actually be page 5)
  3. Display a conditional header for vendor product groups that span multiple pages
    (don’t show products on a given page without making it clear who the vendor is)
  4. Allow catalog to be generated from any found set of products
    (don’t assume that a catalog always consists of all products for all vendors)
  5. Make sure technique is multi-user friendly
    (user A can generate one catalog, while user B simultaneously generates another)

…but I think the most interesting challenge is the generation of the table of contents. The product listing looks like this…

7-13-2013 10-46-14 AM

…and it will provide the basis for the TOC page numbers. The TOC is a list view in the vendor table…

7-13-2013 7-35-49 PM

…with toc_page_number defined thus:

7-13-2013 7-54-01 PM

And this will work because the scripted routine we’re going to look at below will create one variable per vendor id in the TOC.

Also, since a catalog may be generated from a subset of product records, we need to calculate the “page offset” at run time, rather than assuming the TOC will always be three pages long. Reminder: the purpose of the page offset is to ensure a) that page numbers on the TOC are correct, and b) that FileMaker page numbering jibes with the PDF reader’s.

7-13-2013 4-58-56 PM

Here’s the definintion of product::page_number:

7-13-2013 7-54-02 PM

7-14-2013 3-44-46 PMWhen it comes time to generate the TOC, we’re going to “consume” the product listing from the bottom up, looping through the found set backward, popping back and forth between browse and preview modes, omitting records as we go, and declaring variables “dynamically” (which you can read about in depth in Dynamic Variable Instantiation) so we end up with a $variable for each vendor foreign key corresponding to the page where their listing begins.

At any rate, you can see for yourself in the “generate pdf” script, which is extensively commented (at least according to my minimalist standards). Here’s the middle portion…

7-13-2013 8-12-00 PM

Incidentally, the unsung hero of today’s demo is the product::running_count field, which is defined thus…

7-13-2013 3-46-00 PM

…and which not only makes it easy to know how many records to omit during TOC generation, but also instructs conditional headers to only appear when a vendor’s products span multiple pages…

7-13-2013 3-09-47 PM

…i.e., show it most of the time, but hide it under these conditions:

7-13-2013 1-51-18 PM

Well, as the old saying goes, there are many ways to skin a cat(alog). If you’ve grappled with this issue, and come up with an approach you prefer to this one, I hope you’ll post a comment or send me a demo — or better yet, both.

8 thoughts on “PDF Catalog with Table of Contents”

  1. I’m thinking about it. Since an Index comes AFTER the main content it may actually be a bit easier to generate.

  2. Thank you, thank you! This made my day. I just used your basic technique to add page numbers to the Index in a student directory. And, yes, it was easier than the TOC. :) Aloha ~~

  3. Hi, thanks for the useful tutorial. Maybe it’s a stupid question but there is a thing that I don’t understand how is done… in the TOC there are the dots that separate the vendor from the page numbers, and that dots are variable in order to have page numbers aligned on the right… How did you do it? What do I have to insert in the text field to achieve that? thank you

    1. You need to a) insert a single tab character and then b) format the tab stop via the Inspector like so:

Leave a Reply

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