Coldfusion and Updating PDF Documents

I am creating a test page in Dreamweaver to populate a few text fields on a PDF document. This was based off a web tutorial I follwed, but I receive the following error.

The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code. Null Pointers are another name for undefined values.

Very new to this type of coding, so any help would be appreciated.

NACA.pdf is located in the same directory as this cfm.

<cfif isdefined("form.NACA")>
	<cfxml variable="xmlData">
    <cfpdfform action="populate"
<cfform format="flash" preloader="false">
	<cfformitem type="text" style="font-size:14;">Please Log In</cfformitem>
	<cfinput name="NACA" type="text" width="150" label="NACA">
    <cfinput name="Fax" type="text" width="150" label="Fax">
        <cfinput name="submit" type="submit" value="Login">

Open in new window

Michael WilliamsApplication DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi. Your not referencing the form fields in the pdf correctly. Could be the wrong name, or your xml.

First, do this to check the names of the actual fields in the pdf:

<cfpdfform source="NACA.pdf" result="theFields" action="read"/>
      <cfdump var="#theFields#">

then after you know the exact names of the fields, rather than build xml, just use a cfpdfformparam tag. For example,

<cfpdfform action="populate"
        <cfpdfformparam name="NACADate" value="#form.NACA#">
        <cfpdfformparam name="FaxNumber" value="#form.FAX#">

That works for me. Hope this helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michael WilliamsApplication DeveloperAuthor Commented:
That code appears to work. Atleast I don't receive an error : )

How do I display the changes ?
Michael WilliamsApplication DeveloperAuthor Commented:
I guess I should say I want to update fields on a PDF so I can display the result to the user. They would then print the PDF, but the data wouldn't be saved to the actual PDF file.
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

use the destination parameter in the cfpdfform tag to output to a new temp pdf (you can use overwrite = yes to avoid a lot of temp pdf clutter). Then use a cflocation to redirect to the resulting pdf. It should open up in the browser where they can then print or save it locally, and the original NACA.pdf file is unchanged.
Michael WilliamsApplication DeveloperAuthor Commented:
Would you be able to post some sample code ?
Michael WilliamsApplication DeveloperAuthor Commented:
I got it to work. Can you display the PDF without actually saving it to the file system ?
Michael WilliamsApplication DeveloperAuthor Commented:
When doing this type of updating I should obviously update a PDF on the users machine. What the directory this type of stuff should be saved ?
You cannot, as far as I my know-how, force a save on the client machine... unless, you are on a network and there ae shared user folders that the server can access. But, you can force a download of the resulting pdf... Here's how:

create a new script called, getPDF.cfm with the following code inside:

      <cfset LocDir = Replace(GetCurrentTemplatePath(), "getPDF.cfm", "") & "\">
        <cfheader name="Content-disposition" value="attachment;filename=NACAtemp.pdf">
        <cfcontent type="application/pdf" file="#LocDir#NACAtemp.pdf">
        <cflocation url="myMainScript.cfm"> <!--- where myMainScript.cfm is the calling form page --->

now in your main page where the form and form action code is, just have:

        <cfpdfform action="populate" source="NACA.pdf" destination="NACAtemp.pdf" overwrite="yes">
            <cfpdfformparam name="NACADate" value="#form.NACA#">
            <cfpdfformparam name="FaxNumber" value="#form.FAX#">

            <cflocation url="getPDF.cfm">

This will write out the resulting pdf to a temp pdf with your field data filled in, show the download dialogue box for the resulting pdf, and return you to the form. Again, should work, but untested.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.