Copy link to clipboard
Copied
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.
ColdFusion Code
---------------------------------------------------------------------
<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
Miguel F,
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="f
Copy link to clipboard
Copied
Are you running the query in QA to make sure the recordset is being returned and in the right format?
Are you sure the image exists and is in the folder that is being returned in the recordset?
^_^
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Have you tried specifying a URL for the image instead of a physicial path?
Copy link to clipboard
Copied
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?
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-798d.html
^_^
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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:
<cfdump var="#resultStruct#">
Maybe that will shed some light on the issue?
Copy link to clipboard
Copied
Miguel,
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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">
<div>
<p>This is just a test.</p>
<p><img src="/jellyfish.jpg" /></p>
<p>Swatch 1</p>
<p>Orange</p>
<p>Summer 13</p>
</div>
</cfdocument>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
So, theoretically, one could use CFFILE action="readBinary" on the image, and insert the binary into the PDF?
^_^
Copy link to clipboard
Copied
Miguel F,
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>
Copy link to clipboard
Copied
Hey,
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_redacted.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#"/>
<!---</cfpdfsubform> --->
</cfpdfform>
thanks
Dan
Copy link to clipboard
Copied
What are you using to create your PDF form? Are you creating it via LiveCycle and using the Image component? Also, which version of ColdFusion are you on? What happens if you use cfpdfsubform?
Copy link to clipboard
Copied
we are just using ColdFusion 9.0.2 and the cfpdfform tag and creating it on the fly. Is this fix you are showing just for LiveCycle, did i miss that?
Copy link to clipboard
Copied
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)
Download Sample: https://drive.google.com/file/d/0B-EzrYVtdPl6ZVVKOGJQRElYLVU/edit?usp=sharing
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.
Copy link to clipboard
Copied
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.
thanks
dan
Copy link to clipboard
Copied
Hi Bob,
I am trying to accomplish this task as well, and I tried to replicate reading the img file and converting to base64 but I keep getting this error: "
java.lang.ArrayIndexOutOfBoundsException
My PDF was create in Adobe Acrobat Pro DC. I made the image field in the PDF first I tried the names "Image1_af_image" and "Image1".
Then my PDF param variable I did:
<cfpdfformparam name="Image1" imagefield="true" value="#sigImage#" />
AND
<cfpdfformparam name="Image1" value="#sigImage#" />
any ideas?
Thank you in advance.
Copy link to clipboard
Copied
Hi Elampione,
I am trying to do the same thing as you. Did you ever discover a solution for this?
Best regards
Chris