Virtual List Table Of Contents

A few years back I did an article on producing a PDF catalog + table of contents, with the TOC based on a vendor table and the catalog entries based on a products table. Today we’re going to use a different approach to generate a table of contents, building on techniques explored in last year’s Virtual List Reporting series… specifically we’re going to generate one big PDF combining nine reports, prefaced by a table of contents.

2017-01-30_173715

Demo files: virtual-list-toc-v1.zip and virtual-list-toc-v2.zip

2017-01-30_201617

To avoid repetition, today’s article assumes basic familiarity with the virtual list technique (see Virtual List Reporting, part 1 for a general intro, as well as details re: reports 2 – 6, and Virtual List Reporting, part 2 for details re: reports 7 – 9).

Demo 1

Our interest today is primarily focused on the “generate master report w/ t.o.c.” script, which creates the TOC, appends each report, and then displays the PDF.

2017-01-31_083657

Report 1 is a simple listing of sales this month in the amount of $500 or more, and the main purpose it serves is to force our TOC to accommodate a report with a variable number of pages: possibly 8 or 10 towards the end of the month, but it could have zero pages at the beginning of the month, if there have not yet occurred any sales meeting the $500 minimum threshold… in which case the report won’t be generated, and therefore should not appear on the TOC.

And, as mentioned above, reports 2 – 9 were discussed in detail in Virtual List Reporting, part 1 and part 2.

Here’s the TOC in layout mode (based on the virtual list table).

2017-01-30_200641

And here’s the virtual list table during TOC generation.

2017-01-30_200341

The basic plan:

  • Name the report (prompt user via input dialog)
  • Get the page count for report #1
    (we know page counts for the other reports)
  • Generate and output the TOC
  • Generate and append the reports
    (ensuring correct page numbering)
  • Display the PDF

Some general observations about the demo:

1. $$startPage ensures the page number at the bottom of each report page is correct.

2017-01-30_214556

2. Rather than monotonously incrementing the page numbers and calling “report 1”, “report 2”, etc. nine separate times, we use a loop to increment page numbers and invoke the reports via OpenURL — this little trick effectively gives us “perform script by name” capability.

2017-01-30_220319

Demo 2

This demo is identical to “v1” except the hard-coded script names in v1 seem awfully brittle, don’t they? What if we dynamically invoke those scripts by ID instead of by name? Well, we can’t do so directly, but we can do the next best thing: we can detect and store the IDs, and then translate the IDs back into script names (which can be called dynamically) at run time.

We detect the IDs using a variant on FabriceNordmann’s FMNameID custom function, FMNameID_Script, like so…

2017-01-30_212556

…(for more info, see this article: Avoiding Brittleness). The script IDs are loaded into a $var when the master report runs…

2017-01-30_221941

…and then the ids are translated back to script names at run time.

2017-01-30_222212

The benefit of course being that in demo 2 the “report” scripts can be renamed without breaking the master generation routine.

Closing Thoughts

#1. Once again, a huge thank you to Bruce Robertson for inventing virtual list and sharing it with the FileMaker community.

#2. 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?

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.

2 thoughts on “Virtual List Table Of Contents

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s