• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Populating a PDF File from ColdFusion

LEGEND ,
May 16, 2007 May 16, 2007

Copy link to clipboard

Copied


I wanted to populate a pfd file from coldfusion and I found this online:
http://www.school-for-champions.com/coldfusion/cftopdf.htm
When I submit the form.. I then show a link [view pdf].. only when I click
on that lick I get a message saying



Adobe acrobat: the file is damaged and could not be repaired.



Has anyone used this method successfully? If so, would like to hear some
suggestions.



The PDF template I created just have 2 fields. firstname lastname (which
matches cfm form).


Thanks in advance



1. Create PDF document to populate
Create the document you want to populate. This document could be done in
Microsoft Word, as an HTML page or using some drawing application. Then
create a PDF file of that document.

You must have Adobe Acrobat or the equivalent to create a PDF file.
Typically, the easiest way to create a PDF is to click File > Print and
select Acrobat Distiller as your printer.

2. Enter fields with Acrobat
Once the document is in the PDF format, open it in Acrobat. Use the menu bar
tools to define your fields.

a.. Use the Form Tool to define the various text fields, give each a name,
and designate the font type and size. The field name should correspond to
the name of the data you will input.
b.. Use the Text Tool to modify areas of text. You may have to change the
font or font size. It is not the easiest tool to use.
This will be your PDF template.

3. Create a ColdFusion page to populate the PDF
Create a ColdFusion form to gather data from input over the Internet or from
a database query. This page or an action page will provide the means to
populate the PDF file.

The code you use will depend on the method or software you decide to use.
Options will be explained in the next section.




TOPICS
Advanced techniques

Views

3.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 16, 2007 May 16, 2007

Copy link to clipboard

Copied

What version of PDF are you using? Are you creating your PDF Form in designer? If you are trying to Pre-Populate a PDF Form, this technique will not work in that this will not preserve your Form. With the recent versions of PDF, Adobe hase changed the technology to be XML and you are trying to populate your PDF using FDF. I don't think that this can be done.

I would stay away from FDF.

Although there are several tools that will allow you to do this, most of them rely on the old FDF format.

I would suggest checking out XPAAJ. This is a free api for Coldfusion users and offers a decent basic pre-population of PDF's.
Written by our friend Ben Forta, you can check it out here.
http://www.forta.com/blog/index.cfm/2006/7/27/cf_pdfform


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2007 May 16, 2007

Copy link to clipboard

Copied

this works w/the version of iText that comes w/cf7 (powers cfdocument).

<cfscript>
newFile=expandPath("registered.pdf");
// pdf containing your form
pdfFile=expandPath("simpleRegistrationForm.pdf");
fos=createObject("java","java.io.FileOutputStream").init(newFile);
reader=createObject("java","com.lowagie.text.pdf.PdfReader").init(pdfFile);
pdfStamper=createObject("java","com.lowagie.text.pdf.PdfStamper").init(reader, fos);
form1 = pdfStamper.getAcroFields();
// form fields
form1.setField("name", "Bruno Lowagie");
form1.setField("address", "Baeyensstraat 121, Sint-Amandsberg");
form1.setField("postal_code", "BE-9040");
form1.setField("email", "bruno@lowagie.com");
pdfStamper.setFormFlattening(false);
pdfStamper.close();
//
// in case you to "flatten" the form
//
newFile=expandPath("registered_flat.pdf");
fos=createObject("java","java.io.FileOutputStream").init(newFile);
reader=createObject("java","com.lowagie.text.pdf.PdfReader").init(pdfFile);
pdfStamper2=createObject("java","com.lowagie.text.pdf.PdfStamper").init(reader,
fos);
form2=pdfStamper2.getAcroFields();
form2.setField("name", "Bruno Lowagie");
form2.setField("address", "Baeyensstraat 121, Sint-Amandsberg");
form2.setField("postal_code", "BE-9040");
form2.setField("email", "bruno@lowagie.com");
pdfStamper2.setFormFlattening(true);
pdfStamper2.close();
</cfscript>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 17, 2007 May 17, 2007

Copy link to clipboard

Copied

I would second BLXWebMaster's suggestion. We use Ben's <cf_pdfform> tag quite a lot to autofill PDF forms. It even boasts the ability to read data back from PDF forms into CF.

Went to a CF Version 8 Preview today - CF Version 8 will have a <cfpdfform> tag built in to it that will allow you to do pretty much the same thing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2007 May 18, 2007

Copy link to clipboard

Copied

Went to a CF Version 8 Preview today - CF Version 8 will have a <cfpdfform> tag built in to it that will allow you to do pretty much the same thing.

shhh!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 18, 2007 May 18, 2007

Copy link to clipboard

Copied

Its not really a secret. It is in the version of CF8 that I am previewing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 22, 2007 May 22, 2007

Copy link to clipboard

Copied

thanks for the suggestion, I was able to get this to work.
now I was wondering how i can have it instead of displaying the pdf.. create
the pdf and save it and only show it when i click <preview>





"BLXWebMaster" <webforumsuser@macromedia.com> wrote in message
news:f2fi63$c1e$1@forums.macromedia.com...
> What version of PDF are you using? Are you creating your PDF Form in
> designer?
> If you are trying to Pre-Populate a PDF Form, this technique will not work
> in
> that this will not preserve your Form. With the recent versions of PDF,
> Adobe
> hase changed the technology to be XML and you are trying to populate your
> PDF
> using FDF. I don't think that this can be done.
>
> I would stay away from FDF.
>
> Although there are several tools that will allow you to do this, most of
> them
> rely on the old FDF format.
>
> I would suggest checking out XPAAJ. This is a free api for Coldfusion
> users
> and offers a decent basic pre-population of PDF's.
> Written by our friend Ben Forta, you can check it out here.
> http://www.forta.com/blog/index.cfm/2006/7/27/cf_pdfform
>
>
>
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 23, 2007 May 23, 2007

Copy link to clipboard

Copied

PaulH's example using iText will generate a new PDF file for you, which you can later "preview" in the browser.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 30, 2007 May 30, 2007

Copy link to clipboard

Copied

Hi, I need your help again.. And if you can do this for me; i will pay for
your time. just let me know. because i need this project wrap up in the next
28 hours.

I've used the Ben Forta (cf_PDFFROM) and i'm able to get the pdf. (great)

now i need to suppress blank lines.

my pdf is a business card template.

on the left top down

firstname middle name lastname
job title

address1
address2
address3
www.whatever.com

on the right bottom up:
phone:
fax:
mobile:
email:
aim:


there's where I'm stuck:

if a user does not enter a fax number... I want the PDF to move 'phone:'
down 1 line and not show the word 'fax'.


PLEASE can someone point me in the right direction OR tell me you can do it
quickly. contact me and i'll pay you.

thanks in advance!





"BLXWebMaster" <webforumsuser@macromedia.com> wrote in message
news:f2fi63$c1e$1@forums.macromedia.com...
> What version of PDF are you using? Are you creating your PDF Form in
> designer?
> If you are trying to Pre-Populate a PDF Form, this technique will not work
> in
> that this will not preserve your Form. With the recent versions of PDF,
> Adobe
> hase changed the technology to be XML and you are trying to populate your
> PDF
> using FDF. I don't think that this can be done.
>
> I would stay away from FDF.
>
> Although there are several tools that will allow you to do this, most of
> them
> rely on the old FDF format.
>
> I would suggest checking out XPAAJ. This is a free api for Coldfusion
> users
> and offers a decent basic pre-population of PDF's.
> Written by our friend Ben Forta, you can check it out here.
> http://www.forta.com/blog/index.cfm/2006/7/27/cf_pdfform
>
>
>
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 30, 2007 May 30, 2007

Copy link to clipboard

Copied

Could you perhaps create several templates to match the various data configurations and select the one most appropriate for each record?

ie. create a template without the fax and when a record doesn't have a fax number, use that template..


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 31, 2007 May 31, 2007

Copy link to clipboard

Copied

thanks.. I'm creating different templates now!

although I still have to find a solution for down the road..

anyone knows Adobe LiveCycle Designer scripting ?


"efecto747" <webforumsuser@macromedia.com> wrote in message
news:f3lfng$srr$1@forums.macromedia.com...
> Could you perhaps create several templates to match the data and then
> select
> the one most appropriate for each record?
> ie. create a template without the fax and when a record doesn't have a fax
> number, use that template..
>
>
>
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 31, 2007 May 31, 2007

Copy link to clipboard

Copied

Sounds like a scenario for....

CFIF Fax is null, use template 1
CFIF Address2 is null, use template 2

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 31, 2007 May 31, 2007

Copy link to clipboard

Copied

tclaremont wrote:
> Sounds like a scenario for....
>
> CFIF Fax is null, use template 1
> CFIF Address2 is null, use template 2

you're going to need an awful lot of templates ;-)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 01, 2007 Jun 01, 2007

Copy link to clipboard

Copied

exactly.. that's why for a short term solution 1 day.. i did a few templates.

but i need to work off of ONE master. and i'm still having problem suppress the lines when it's empty.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2007 Jun 01, 2007

Copy link to clipboard

Copied

indranie wrote:
> exactly.. that's why for a short term solution 1 day.. i did a few templates.
>
> but i need to work off of ONE master. and i'm still having problem suppress the lines when it's empty.

for anything complex i always use iText (anything less complex you *cannot* beat
cfdocument, it makes PDF production drop dead simple, especially from HTML). you
probably want to use the latest version of iText & the easiest way to do that &
*not* break cfdocument is to use mark mandel's javaloader to "load" the new
iText jar ( http://javaloader.riaforge.org/ ). use iText to read the PDF form,
extracting the field values & then simply "burn" a new PDF using the form data.

if you do a lot of work w/iText you should probably get bruno's book:

http://itext.ugent.be/itext-in-action/

it's worth it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 03, 2007 Jun 03, 2007

Copy link to clipboard

Copied

So, you have 5 fields like what is below. If the value for any field is Null, you want to supress that line from being drawn.

Are these individual fields? If so, do the need to be? What about creating 1 Text area field and populating the whole thing instead of seperately. This way, in your CF code you could do somethign like this....

<cfsavecontent variable="ContactInfo">
<cfif Form.phone NEQ ''>phone: #Form.Phone# <BR></cfif>
<cfif Form.fax NEQ ''>fax: #Form.fax# <BR></cfif>
<cfif Form.mobile NEQ ''>mobile: #Form.mobile# <BR></cfif>
<cfif Form.email NEQ ''>email: #Form.email# <BR></cfif>
</cfsavecontent>

Then just pass ContactInfo to your PDF.

Allen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2007 Jun 01, 2007

Copy link to clipboard

Copied

Hey, I didn't say it wouldn't be labor intensive! 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 01, 2007 Jun 01, 2007

Copy link to clipboard

Copied

What about using iText to create your PDF programatically? Then you could position your content however you'd like.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 04, 2007 Jun 04, 2007

Copy link to clipboard

Copied

LATEST
Allen,
Unfortunately, this particular case IS is trying to precisely position the elements in the PDF (its a business card template), so the HTML to PDF via CFdocument route isn't really going to work for him.

I do have to say, the few times I have used iText it's been pretty effective. You may run into some issues in a hosted environment (restricted use of CreateObject() or <cfobject>, etc). Mark Mandel's javaloader is a pretty cool tool, thanks for the link Paul.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation