Open PDF bookmarks bar on open with CFDocument javascript and DDX

Recently I was tasked with what seemed like the impossible. I needed to have PDF's that were generated with CFDocument to auto expand the bookmarks bar in compatible PDF readers. Initially I thought it was impossible to do this after googling for a solution. However I did eventually find a solution hidden away in an Adobe help forum.

The solution was to write document level javascript that can included in the PDF via DDX and fires when the document is opened in a PDF Reader. The documentation for how to include document level javascript in a CFDocument generated PDF was not easy to find so I thought I would make it easy for the next person searching for this.


Including Images in a PDF created in CFDOCUMENT

One problem that I ran into while creating PDF's recently in Coldfusion 8 was with including images. Despite using what I thought was a valid path (since it would show up in my browser) and using the correct syntax, my images were showing up as red x's. I found out that there is a little trick to including images in a PDF in CF.


Creating PDFs from scratch in Coldfusion 8

I figured when I first started this project that it would require the use of CFPDF in order to create a PDF in Coldfusion - wrong. CFPDF is only used to manipulate already existing PDF's.

It is the CFDOCUMENT tag that you use to actually do the initial creation.

Here is an example of how you would create a PDF and output it to the browser window: