[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Coldfusion and Updating PDF Documents

Posted on 2008-11-18
9
Medium Priority
?
374 Views
Last Modified: 2013-12-24
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

0
Comment
Question by:Michael Williams
  • 5
  • 3
8 Comments
 
LVL 2

Accepted Solution

by:
mtgenus earned 2000 total points
ID: 22995848
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
 

Author Comment

by:Michael Williams
ID: 22996277
That code appears to work. Atleast I don't receive an error : )

How do I display the changes ?
0
 

Author Comment

by:Michael Williams
ID: 22996411
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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
LVL 2

Expert Comment

by:mtgenus
ID: 22996609
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
 

Author Comment

by:Michael Williams
ID: 22996672
Would you be able to post some sample code ?
0
 

Author Comment

by:Michael Williams
ID: 22996767
I got it to work. Can you display the PDF without actually saving it to the file system ?
0
 

Author Comment

by:Michael Williams
ID: 22996789
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
 
LVL 2

Expert Comment

by:mtgenus
ID: 22997882
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

*Adobe Acrobat 9 was used for this article. Particular steps may vary depending on software versions. 1. Create a framework of your form in Word, leaving space where you’d ultimately like the Adobe fields to appear.  (Note: I use the blank lines …
In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question