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

Michael WilliamsApplication DeveloperAsked:
Who is Participating?
 
mtgenusConnect With a Mentor Commented:
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"
        source="NACA.pdf">
        <cfpdfformparam name="NACADate" value="#form.NACA#">
        <cfpdfformparam name="FaxNumber" value="#form.FAX#">
</cfpdfform>

That works for me. Hope this helps.
0
 
Michael WilliamsApplication DeveloperAuthor Commented:
That code appears to work. Atleast I don't receive an error : )

How do I display the changes ?
0
 
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.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
mtgenusCommented:
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.
0
 
Michael WilliamsApplication DeveloperAuthor Commented:
Would you be able to post some sample code ?
0
 
Michael WilliamsApplication DeveloperAuthor Commented:
I got it to work. Can you display the PDF without actually saving it to the file system ?
0
 
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 ?
0
 
mtgenusCommented:
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.



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.