I created a simple LiveCycle PDF that has 1 image and 3 textfields. Using the ColdFusion code below, I was able to pass data from ColdFusion into the form. However, I can't figure out how to dynamically populate the image. When I run the code, the image is always empty.
Does anyone know how to do this? All of my image paths are stored in a database and need to be dynamic.
<cfpdfform source="c:\webs\testpdf.pdf" destination="c:\webs\result.pdf" action="populate" overwrite="true"> <cfpdfsubform name="form1"> <cfpdfformparam name="img1" value="C:\webs\jellyfish.jpg"/> <cfpdfformparam name="txt1" value="Swatch 1"/> <cfpdfformparam name="txt2" value="Orange"/> <cfpdfformparam name="txt3" value="Summer 13"/> </cfpdfsubform> </cfpdfform>
Note: Using ColdFusion 9
This is just a simple test file so there are no queries or dynamic variables. Just hardcoded values. As you see in my code snippit above, all <cfpdfformparam> values are set with string values. When I run the code, all three textfields are populated perfectly. The image however doesn't appear. I'm not sure why. The image does exist in the folder specified. The .cfm PDF creation script exists in the same folder as well.
I was just about to suggest using a relative web path instead of a full physical path.
Also, you have the overwrite parameter, but you do not have the overwriteData parameter. That might fix it?
Yeah. I've tried replacing "
C:\webs\jellyfish.jpg" with all sorts of variations. Including "jellyfish.jpg, ./jellyfish.jpg, file:///C|/Webs/jellyfish.jpg, C:\Webs\jellyfish.jpg". I've never had generate a dynamic PDF with images. The text input controls in PDF forms are pretty straight forward. I'm assuming that the image control in the PDF LiveCycle form should just accept a path to the image, go grab the image, and then embed it in the created PDF. Although, since i've never had to do this, I'm not sure if it works that way. Have you guys had to do this in the past?
I have not used the cfpdfform tag before. Looking at the documentation I read this:
Use subforms to match the exact structure of the source PDF form. If you do not, ColdFusion cannot prefill the form with data and generates an error. Many of the forms generated from templates in LiveCycle contain a subform called form1. You must specify this as a subform in your code, as the following example shows:
It looks like you are doing this already but I was just wondering if you verified the structure of your PDF as documented. Like this:
To verify the structure of a PDF form in ColdFusion, use the read action of the cfpdfform tag, as the following example shows:
<cfpdfform source="c:\forms\timesheetForm.pdf" result="resultStruct" action="read"/>
Then use the cfdump tag to display the structure:
Maybe that will shed some light on the issue?
I'm actually trying to do the opposite. I'm trying to write a PDF file. I've succesfully written text from ColdFusion to a my PDF form. However, I'm trying to pass an image path from ColdFusion into my PDF image control.
I thought you were trying to fill in form information using ColdFusion into a PDF document that you had already created using something else??? Looking at your code it references a source PDF file. I thought that debugging code I mentioned might help because it should show you how ColdFusion "sees" the layout of your existing PDF file. Maybe the image control is embedded in a different layer (element) than you think. Or maybe ColdFusion doesn't see the image control at all. Try those two lines of code on your source PDF and reply back what the results are. It might help.
I read it wrong the first time around. Sorry for the miscommunication. This did help debug the PDF form. The screenshot shows the dump of the form that was created like you suggested and I also attached a screenshot of the PDF result. As you can see, all three of textfields populated correctly. The image field is being set to "/jellyfish.jpg", but it doesnt show on the form. Any suggestions where to go from here?
In your initial example you were setting img1 to "C:\webs\jellyfish.jpg" (with the path).
<cfpdfformparam name="img1" value="C:\webs\jellyfish.jpg"/>
Is that still the case in your screen shot example? Just curious because the dump only references "/jellyfish.jpg". Maybe you changed the code since then.
Can you see the image if you surf to your website/jellyfish.jpg ?
In the pdf form what kind of input is "img1"? I can assume that the other three fields are simply text inputs but what is an image input?
As I mentioned before, I have never really used the cfpdfform tag before but I am trying to help you "debug" it. So I'm not really sure what syntax it expects for an image input? I have used the cfdocument tag before and embedded images with it. That tag has an attribute named "localurl" that lets you specify whether you want to use a physical path to your image or a URL to your image. I'm not sure if the cfpdfform tag has anything similar?
Can you create this test template and see if it works for you?
<cfdocument format="PDF" localurl="false">
<p>This is just a test.</p>
<p><img src="/jellyfish.jpg" /></p>
I was trying different paths to see if it would work. The dump shows that data is being passed into that image component. But, no image is showing. I'm actually kind of curious if its assigning the path to a wrong property.
I'm using Adobe LiveCycle to create the form template. Within LiveCycle they have pre-built objects you can drag onto the canvas. I'm using text field's for my text items and i've tried both image field and image for my image placeholder. (See Screenshot)
I ran the <cfdocument> code you supplied. It does work using the HTML to create a PDF. Although, the customer has an existing PDF template that might be kinda tedious to recreate in HTML. Ideally, it would be nice if I can just populate the template objects. But, the cfdocument will be a good alternative if I can't figure out the LiveCycle PDF way.
Maybe we have been going about this in the wrong way. I just found a previous post and according to the last suggestion the image field is actually wanting the image binary data, not a reference to the image. I guess that makes sense if the image is to be embedded in the PDF file.
See this post (the last reply): http://forums.adobe.com/message/1891327
You are right man. I used the ToBase64() and it worked like a charm. Here is my end code. I guess that Image Field needs binary data to embed the image. Thanks for all your help!
<!---Read in the file---> <cfimage action="read" source="jellyfish.jpg" name="myImage"> <!---Convert it to Base64---> <cfset myImage = ToBase64(myImage)> <!---Write the PDF file---> <cfpdfform source="c:\webs\testpdf.pdf" destination="c:\webs\result.pdf" action="populate" overwrite="true"> <cfpdfsubform name="form1" index="1"> <cfpdfformparam name="img1" value="#myImage#"/> <cfpdfformparam name="txt1" value="Swatch 1"/> <cfpdfformparam name="txt2" value="Orange"/> <cfpdfformparam name="txt3" value="Summer 13"/> </cfpdfsubform> </cfpdfform>
so I am trying to do the same thing you are, but not using the cfpdfsubform tag. When I use your code but replace pdf files with mine, and the image with mine, i just get some text string or url in the field i need.
any thoughts on why this might now work for me?
<cfimage action="read" source="C:/LOCALSERVER/appFolderName/includes/images/common/lab_redac ted.gif" name="myImage">
<cfset myImage = ToBase64(myImage)>
<!---Write the PDF file--->
<cfpdfform source="c:/localserver/currentFolder/Library/DocumentName.pdf" destination="c:/inetpub/wwwroot/redactedPDFImageTest.pdf" action="populate" overwrite="true">
<!---<cfpdfsubform name="form1" index="1">--->
<cfpdfformparam name="VISA_CLASS_ID" value="H-2A" />
<cfpdfformparam name="TMP_JOB_TITLE" value="N/A" />
<cfpdfformparam name="EMP_FEIN" value="#myImage#"/>
I created my PDF template first using Adobe LifeCycle Designer and then populated it on the fly with dynamic images and data. You can use the link below to download a sample project I've created to give you a live demonstration of how I handeled this.
Just place the folder in your web root and execute the file pdfWithoutMerge.cfm. (http://localhost/pdfBug/pdfWithoutMerge.cfm)
I eventually ended up using <cfdocument format="pdf"> to accomplish the task. However, even that was a little painful. It doesn't accept CSS very well. I was just at the ColdFusion Summit in Las Vegas. They are working on improving the PDF functionality within ColdFusion 11. So, for now I recommend either using LiveCycle to create your template or writing HTML to a PDF using <cfdocument format="pdf">. I don't beleive Acrobat supports dynamic image injection. However, I could be wrong.
So we don't have LiveCycle, so we can't use that...unless I am missing something about liveCycle..
We are using cfpdf not cfdocument, and the templete file is already created. From other posts sounds like the only way to add an image into our PDF file is to change the field to an image field, however i am updating this field if certain users see it, there field needs to have a black image/bar over the data, else they need to see the data...so not sure how changing the filed will help. I have 2 other ideas, DDX (which i know nothing about), and watermarks...i am going to try watermarks, which other coworkers have had varying degrees of success...and i hope to get some feedback about DDX.
I tried to get around at CFSummit to talk to many people, but 500 is just a bit hard to get to everyone...so i probably did not get to talk to you unless you were in the BOF about User Groups or at the Adobe Dinner on Friday night.
We'll, i'll keep working through this and see how it works.