Questions on populating a PDF form with cfpdfform and rich text

418 views Asked by At

So I'm using the following code to create a PDF from data from a query.

<cfpdfform action="populate" source="test.pdf" destination="GeneratedPDFs/test.pdf" overwrite="yes">

<cfpdfformparam name="FirstLine1" value="#Variables.FirstLine#">    
<cfpdfformparam name="SecondLine1" value="#Variables.SecondLine#">    
<cfpdfformparam name="AddressBox1" value="#Variables.AddressBox#">    
<cfpdfformparam name="Body1" value="#Variables.Body1#">

<cfpdfformparam name="FirstLine2" value="#Variables.FirstLine#">    
<cfpdfformparam name="SecondLine2" value="#Variables.SecondLine#">    
<cfpdfformparam name="AddressBox2" value="#Variables.AddressBox#">    
<cfpdfformparam name="Body2" value="#Variables.Body2#">

</cfpdfform>

<cfpdf action="write" source="GeneratedPostCards/!PostCard2013-Vipre.pdf" destination="GeneratedPostCards/!PostCard2013-Vipre-flat.pdf" flatten="yes" overwrite="true">

</cfpdf>

This works fine, and generates the PDF for me, but I've run into three issues:

  1. If I set a form field in Acrobat Pro DC to a Rich Text, then no matter what font I select, I get Courier. In order to get the font I want, I have to turn off Rich Text.

  2. I'd like to change the line spacing or leading in the multi-line fields, but I don't see a way to do that (either in Acrobat or in ColdFusion).

  3. I'd like to be able to bold, italicize, and change the colour of specific words (not the entire field) and I'm wondering if there are codes I can pass from ColdFusion to do this.

Thanks!

1

There are 1 answers

0
Max Wyss On

Keep in mind that if you set the richText flag of a text field, you will have to use richValue for the value, and richValue is an array of span objects, where each object represents a piece of the text with specific properties. The Acrobat JavaScript documentation is your friend…

As it is not really possible to directly insert arrays into a PDF form, you might consider representing the richValue arrays as strings, and fill them into hidden "shadow fields". When the document opens, some logic interprets those strings, and fills the richText enabled fields with correct richValue arrays.

It may also be good to know that there is no richDefaultValue property, which means that you would have to recreate the richValue when you reset the form.