A reader wrote in to me with an interesting question yesterday. He was using ColdFusion 9's nice new ability to work with Office documents to create a merged PDF of various sources. His application let people drag and drop different documents into the browser (using HTML5) and then make use of cfdocument to convert them all into PDFs. Once done, all the PDFs would then be merged into one PDF.
This worked fine, but he ran into a problem when PDFs were part of the bunch of files that were to be merged. Obviously he didn't need to convert PDFs to PDFs, but because he wasn't using cfdocument to create the result, the PDF sources didn't have bookmarks. His final merged PDF would have a bookmark for all the bits except inner PDFs.
I double checked the docs and saw no way to add a bookmark to an existing PDF. You can't source cfdocument with a PDF. You can't do it with cfpdf either. Luckily though DDX once again came to the rescue. I noticed that the DDX example in the docs made use of the PDF tag to do a merge. (Which isn't necessary anymore since we can do merges with CFPDF.)
<?xml version="1.0" encoding="UTF-8"?>
<DDX xmlns="http://ns.adobe.com/DDX/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd">
<PDF result="Out1">
<PDF source="Title"/>
<TableOfContents/>
<PDF source="Doc1"/>
<PDF source="Doc2"/>
<PDF source="Doc3"/>
</PDF>
</DDX>
On a whim I looked up the reference for the PDF tag in DDX and discovered that it includes a "bookmarkTitle" attribute. Here is a sample script I used:
<cfsavecontent variable="ddx">
<?xml version="1.0" encoding="UTF-8"?>
<DDX xmlns="http://ns.adobe.com/DDX/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd">
<PDF result="Out1">
<PDF source="Doc1" bookmarkTitle="TESTING!!" />
</PDF>
</DDX>
</cfsavecontent>
And it worked like a charm. I took a random PDF as my source and when I checked the output, the "inner" PDF had a bookmark called "TESTING!!".
Archived Comments
This works great, but does not work with XFA pdfs. So if you created the pdf via LC Designer you will need to find another way, or transform them if you own LC.
Commented to soon,
<cfpdf action="write" source="pdetail_static.pdf" destination="pdetail_flat.pdf" flatten="yes" overwrite="true">
However - I also needed to save the PDF from inside LC Designer as a PDF Static and not dynamic.
Check out this doc for more on the difference:
http://help.adobe.com/en_US...
I am now also getting a popup when I opened the PDF telling me a need a newer version of Acrobat. Not sure how to get around that one yet.
Also check out http://old.nabble.com/CFPDF...
for a workaround for page numbering after a merge. Fix is due for CF10.
Using the flatten prior to the merge works!!
Thanks for the updates Mike!
Ray - Great work on putting these guides together for PDF creation and manipulation. It helped me get a project working with a full ToC and nested bookmarks. I so wish that ACF had a create ToC function for CFPDF, or even an option when merging documents to create it. Maybe in the next version?
@Reuben: Remember you can always make a request like this here:
http://cfbugs.adobe.com/cfb...
No guarantee Adobe will add it - but you should at least request it.
Maybe I should help the Railo and OpenBD guys implement it in their CFPDF implementations ;)
Some PDFs I download open the bookmark toolbar by default, while the PDFs I create in ColdFusion do not. Is there a way to force open the bookmark toolbar when I create my PDF from ColdFusion? It's apparently a property of the document.
Thanks!
Going by memory here as I'm on the road- but I believe this can be done via DDX. There is a way to set the opening state of the PDF. Do some research into CF and DDX (I have some posts here) and you may have success.