Skip to main content
Inspiring
August 24, 2012
Answered

How do I populate PDF Image from ColdFusion?

  • August 24, 2012
  • 3 replies
  • 12701 views

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

This topic has been closed for replies.
Correct answer BobKlaas

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


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>

3 replies

August 11, 2020

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.

Participant
June 17, 2023

Hi Elampione,

I am trying to do the same thing as you. Did you ever discover a solution for this?

 

Best regards

Chris

Known Participant
November 13, 2013

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

BobKlaasAuthor
Inspiring
November 13, 2013

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?

Known Participant
November 13, 2013

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?

WolfShade
Legend
August 27, 2012

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?

^_^

BobKlaasAuthor
Inspiring
August 27, 2012

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.

Miguel-F
Inspiring
August 27, 2012

Have you tried specifying a URL for the image instead of a physicial path?