Monday, April 21, 2008

Populate and Merge multiple pdf forms

If you need to populate multiple PDF forms and then merge them together... Here is how to do that.


<cfset sourceform1 = "#ExpandPath('formsamples/expense_claim_form1.pdf')#">

<cfset sourceform2 = "#ExpandPath('formsamples/expense_claim_form2.pdf')#">
<cfset resultfile1 = "#ExpandPath('result1.pdf')#">
<cfset resultfile2 = "#ExpandPath('result2.pdf')#">
<cfset flatfile1 = "#ExpandPath('flat1.pdf')#">
<cfset flatfile2 = "#ExpandPath('flat2.pdf')#">
<cfset finalresultfile = "#ExpandPath('finalresult.pdf')#">
<cfset myname1 = "source_test1">
<cfset myempcode1 = "source_code1">
<cfset mylocation1 = "source_loc1">
<cfset mymgrname1 = "source_mgr1">
<cfset mymgremail1 = "">
<cfset myname2 = "source_test2">
<cfset myempcode2 = "source_code2">
<cfset mylocation2 = "source_loc2">
<cfset mymgrname2 = "source_mgr2">
<cfset mymgremail2 = "">
<!--- Fill up the pdf form1 ---> 
<cfpdfform source= "#sourceform1#" action="populate" destination="#resultfile1#" overwrite="true">
 <cfpdfsubform name="form1">
  <cfpdfsubform name="expense">
   <cfpdfformparam name="name" value="#myname#">
   <cfpdfformparam name="empcode" value="#myempcode#">
   <cfpdfformparam name="location" value="#mylocation#">
   <cfpdfformparam name="mgrname" value="#mymgrname#">
   <cfpdfformparam name="mgremail" value="#mymgremail#">
<!--- Fill up the pdf form2 ---> 
<cfpdfform source= "#sourceform2#" action="populate" destination="#resultfile2#" overwrite="true">
 <cfpdfsubform name="form1">
  <cfpdfsubform name="expense">
   <cfpdfformparam name="name" value="#myname#">
   <cfpdfformparam name="empcode" value="#myempcode#">
   <cfpdfformparam name="location" value="#mylocation#">
   <cfpdfformparam name="mgrname" value="#mymgrname#">
   <cfpdfformparam name="mgremail" value="#mymgremail#">
<!--- Flatten the filled-up pdf forms first. --->
<cfpdf action="write" source="#resultfile1#" destination="#flatfile1#" flatten="yes" overwrite="true">
<cfpdf action="write" source="#resultfile2#" destination="#flatfile2#" flatten="yes" overwrite="true">
<!--- Now merge the flattened forms. ---> 
<cfpdf action="merge" source="#flatfile1#,#flatfile2#" destination="#finalresultfile#" overwrite="true">



Javi said...


Thanks so much for the post! The only problem though is that this is for Acrobat made only PDFs correct?

The problem we are running into is that we are trying to populate several dynamic PDFs made in LiveCycle Designer and then merge them into 1 PDF. The docs state though that you cannot flatten LiveCycle Designer made docs. Can we still achieve this by using PDFs created in LiveCycle Designer?

Note that everything works fine, even the merging, its just that when we assemble the XFA (xmlData) populated PDF's the data for each of the fields no longer shows up in Acrobat Reader. Is what I'm trying to build achievable or do I need to use DDX? Or revert my forms into Acrobat ones? Thanks again for taking the time to post about this!

ahamad said...

Hi Javi,
Can you send across the some sample forms and code so that I can test it on my side here...


Morgan said...


Just wanted to say that I have the same challenge as Javi.

Feels strange if we cannot flatten LiveCycle created forms...

Sven Ramuschkat said...

the possibility to flatten real LC Designer Forms would we a great feature to ColdFusion, because I makes no sense to use the old AcroForms anymore.

The only way to flatten LC forms today is to use LC Output, which is really expensive ;-(


Greg said...

Ahamad, thanks for the great blog. As already noted, flattening works only for AcroForms(not LiveCycle Designer XFA Forms).

I use CFPDF action="populate" to pre-fill Designer XFA forms.

Our problem is that not every one of our customers can view these forms because they don't have Acrobat/Reader 8. We also have a print center that is not PDF1.7 compatible. They can only handle PDF1.4 format.

I have been trying to figure out a way to flatten these pre-filled XFA forms (convert to PDF1.4) since the ColdFusion 8 pre-release program.

So far I haven't had much luck. Are their any solutions available yet like:

1) DDX
2) silent command-line call to acrobat/reader similar to File>Print>Adobe PDF>Print to file?
3) PDF Library API

Thanks for all your help.


Anonymous said...

I use cfdocument to print out personnel biographies. You select an employee, click print, and bam, a .pdf is generated. What I need to do is allow a user to pick a few biographies, and click print and generate one pdf with multiple biographies. Not sure how to accomplish this... any suggestions?

Joe Zack said...

It sounds like I'm running into the same problem as everyone else. Anyone come up with a solution yet?

cw said...

It appears that I have run into this problem as well. I reported it as a bug. How are we supposed to merge multiple LiveCycle forms together?

This seems kind of weird that they don't support this? Were they testing it on an old version of Adobe?

ahamad said...

As such we have certain known issues with the CF8.0 build.
1. XFA Forms(Livecycle) forms cannot be flattened.
2. If you merge a PDF Form with an existing PDF, the form data is lost in the resultant pdf – I think this has been fixed for updater.(I need to verify this)
3. cfpdf – merge – You cannot merge two pdfforms; you can merge pdf files.

There are certain implementation difficulties but still we are working on these.

Anonymous said...

Good post.

Remember to flatten your files, or else the form values you enter will get stripped out.

Anonymous said...

Good post and this fill someone in on helped me alot in my college assignement. Say thank you you as your information.

Anonymous said...

Нло и непознанное

Anonymous said...

Супер современные новости http://новостипланеты.рф

Anonymous said...

все о науке

Anonymous said...

Библиотека для всех

Anonymous said...

Добро пожаловать на сайт http://эространа.рф качественные фото девушек.

Anonymous said...

[url=]online casino[/url], also known as accepted casinos or Internet casinos, are online versions of household ("amigo and mortar") casinos. Online casinos own gamblers to gather ingredient in and wager on casino games from guv to foot the Internet.
Online casinos typically chance on the huckster odds and payback percentages that are comparable to land-based casinos. Some online casinos swing establishment higher payback percentages payment douse gismo games, and some take a chance at big payout capacity audits on their websites. Assuming that the online casino is using an okay programmed indefinitely copse generator, scantling games like blackjack clothed an established obstruction edge. The payout interest as a replacement representing these games are established via the rules of the game.
Uncountable online casinos sublease in dishonour or apprehension their software from companies like Microgaming, Realtime Gaming, Playtech, Worldwide Circumvent Technology and CryptoLogic Inc.

Anonymous said...

top [url=]uk online casino[/url] coincide the latest [url=]free casino bonus[/url] autonomous no store bonus at the best [url=]casino games

Anonymous said...

top [url=]free casino bonus[/url] check the latest [url=]free casino[/url] unshackled no consign hand-out at the best [url=]bay take note of casino

Anonymous said...

Hello there! I do know this can be to some degree off-topic
nonetheless needed to consult. May owning a well-established website similar to the one you have take a wide range of
do the job? My business is completely new so that you can
blogs but I conduct produce around my journal everyday.
I’d like to begin a weblog to promote my very own experience in addition to views
on the internet. You should tell me if you have virtually any recommendations and
also tricks for fresh wannabe web site masters. Regards!
Feel free to visit my webpage Kitchen refacing

Anonymous said...

garcinia cambogia benefits[/url] is the rout adipose burning force out nearby in hawk contemporarily a days. Lose upto 10 kg in 1 month. garcinia cambogia select

Anonymous said...

Children raised on upbeat are is in the display, this one is portable! [url=]online casino[/url] online casino games Microgaming is one of the are very very much pop among amateur players.

Anonymous said...

Moreover, your unsecured financial loan quote discloses home loan been given still being third party your first however may be to go right down to your local bank Click HERE Very notably, pop pundit Jon Stewart in the Daily Indicate absolutely skewered Gov

pakistannationalnews said...

"Man Pasand Shadi"">Rohani Wazifa"">Taweezat"">Black magic
The Istikhara is an Islamic tradition which is strongly rooted in our culture of Iran, India and Pakistan. Amil Bangali Baba"