Skip to main content
Inspiring
November 20, 2024
Question

Populating an image field in a PDF with Coldfusion

  • November 20, 2024
  • 1 reply
  • 3248 views

Hello!

 

I'm trying to add a GIF file to a PDF using the CFPDFFORMPARAM tag and not having any success. Attached is a code snippet and a screenshot of the output PDF.

 

The 'sig' form field is just a plain text field, but you can see that the data is captured and being put in. the 'Image1' form field is an image field. I cannot get it to display the actual image. On the output screenshot, the image field and text field are side by side.

    1 reply

    BKBK
    Community Expert
    Community Expert
    November 21, 2024

    That should work. However, in the PDF form, the fields Image1 and sig should not be text type.

    Review the PDF form and make sure those fields are suitable for image, not text.

    Participating Frequently
    March 18, 2025

    I have the same code and issue populating a sample PDF I created using Adobe Acrobat.  The image is not displayed in the resulting pdf but if I use <cfimage action="writetoBrowser" source="<the image fieldname from the pdf results" format="png"/>, I'll get the image to display properly in my browser.  So I know the image data was written to the pdf but it's just not visible.

     

    The original issue (CF-4210894 | Tracker) was brought up in the following ticket and a fix was part of ColdFusion 2021 Update 17.  Apparently this isn't working for me at least.  I'm using ColdFusion 2021 Update 18.

    BKBK
    Community Expert
    Community Expert
    March 19, 2025

    Hi @Marcus335807545qqw , thanks for sharing the link to the bug ticket about the issue (CF-4210894 | Tracker) . The ticket contains an example, attached as a ZIP file.

     

    I therefore ran a test on ColdFusion 2021 Update 18, based on the example. The result is that the image field in a PDF form can be populated.

     

    Should you wish to reproduce my test, here are the steps:

    1.  Download the ZIP file attached to the bug ticket (cfpdfform-image.zip) and extract it.
    2.  Under your web-root, create a test directory called cfpdfform_insert_image. Copy into this directory the files car-photo.jpg and Example-button.pdf from step 1.
      Confirm that the image in Example-button.pdf looks like this:
    3.  Within the directory cfpdfform_insert_image, create a CFM file called imageTest.cfm. Copy-paste the following code into the CFM file:
      <cfset testPDFForm = expandPath("Example-button.pdf")>
      <cfimage action="read" source="#expandPath('car-photo.jpg')#" name="photoBinary">
      
      <cfpdfform action="populate" source="#testPDFForm#" destination="#expandPath('Updated_PDF_Form.pdf')#" overwrite="true" overwritedata="true">
      	<!--- The field name 'vehicle_photo' is the one specified in Acrobat Pro when creating the PDF form.--->
      	<cfpdfformparam name="vehicle_photo" value="#toBase64(photoBinary)#" imagefield="true">
      </cfpdfform>
      
      Done.<br>
      Now, examine the file 'Updated_PDF_Form.pdf' in the current folder, and confirm that the image in the PDF form has been updated.
    4.  Launch the page imageTest.cfm.
           When you inspect the file Updated_PDF_Form.pdf, you should see that the image now looks like this: