ColdFusion: how to populate livecycle pdf section dynamically using query data

1.1k views Asked by At

I have a template PDF that has a section that will be laid out like a table. The data will come from a query. So this table will be dynamic, number of rows unknown.

How do I accomplish this using ColdFusion? Is it a combination of creating a template using LiveCycle and creating this section so it is dynamic and then using CFPDF to populate it.

Right now I'm using to populate static fields.

<cfpdfform source="Template.pdf"
   destination="Template2.pdf" action="populate">
   <cfpdfsubform name="form1">
    <cfpdfformparam name="pdf_controlNum" value="123">
    <cfpdfformparam name="pdf_ReportDate" value="05/01/2012">
   </cfpdfsubform>
</cfpdfform>
2

There are 2 answers

1
Merle_the_Pearl On

Did you just want to create a PDF File? If so you also have to call in the style sheet after the cfdocument

<cfdocument 
format="pdf" 
filename = "pdf_file_path\#pdf_controlNum#_#pdf_ReportDate#.pdf"
overwrite = "yes"
marginBottom = ".2"
marginLeft = ".4"
marginRight = ".4"
marginTop = ".2">

<style type="text/css">@import "pdf.css";</style>

QUERY RESULTS TABLES AND CODING HERE ETC

</cfdocument>
2
Larry On

I found the solution. It was in this forum:

http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_26528588.html

At bottom of thread was this:

2 key points 1. in cf you need to set overwritedata=”yes” in cfpdfform 2. the pdf needs to be a dynamic pdf.

hope this helps others. I don't have a how to blog but if you know of one just let me know. Very handy indeed.

<cfpdfsubform name="details">    
  <cfpdfsubform name="Table1">
    <cfloop from="1" to="#getClientOrderDetails.recordCount#" index="i">            
      <cfpdfsubform name="Row1" index = "#i#">  
      <cfpdfformparam name="pdfDescription" value="#getClientOrderDetails.ItemDescription[i]#">
        <cfpdfformparam name="pdfItemQuantity" value="#getClientOrderDetails.ItemQuantity[i]#">
        <cfpdfformparam name="pdfItemUnitPrice" value="#getClientOrderDetails.ItemUnitPrice[i]#"> 
      </cfpdfsubform>
    </cfloop> 
   </cfpdfsubform>
 </cfpdfsubform>