Link to home
Start Free TrialLog in
Avatar of Michael Williams
Michael WilliamsFlag for United States of America

asked on

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">
    	<cfoutput>
        <data>
           	<NACADate>#form.NACA#</NACADate>
            <FaxNumber>#form.FAX#</FaxNumber>
        </data>
        </cfoutput>
    </cfxml>
    
    <cfpdfform action="populate"
    	source="NACA.pdf"
        XMLdata="#xmlData#"/>
	<cfabort>
</cfif>
 
<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">
</cfform>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mtgenus
mtgenus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael Williams

ASKER

That code appears to work. Atleast I don't receive an error : )

How do I display the changes ?
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.
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.
Would you be able to post some sample code ?
I got it to work. Can you display the PDF without actually saving it to the file system ?
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#">
        </cfpdfform>

            <cflocation url="getPDF.cfm">
       <cfabort>

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.