Page 1 of 1

Submitting a PDF form to a PHP script

Posted: Wed Jan 21, 2009 11:40 am
by rhecker
We have a form that we want users (the public) to submit to our server. It's easy to se the submit button to email the PDF or FDF, but too many people use computers that do not have email accounts set up, which makes this method unreliable.

I can create an html form or even a PDF form that posts data to a PHP script that builds a FDF file and emails a link (from the server) to staff, who can open it in a PDF.

BUT, what I would like to do is simply submit the PDF the user fills out to a PHP script that will then name the file (date string) and store the whole PDF on the server, where staff can retrive it later. Seems simple, but have not discovered how to do this.

Any thoughts? Thanks.

Re: Submitting a PDF form to a PHP script

Posted: Wed Jan 21, 2009 11:42 am
by Burrito
best solution would be to write the .fdf on the server then redirect users to the .fdf (on the server) and use the FQDN in the .fdf to open the .pdf in the user's browser.

Re: Submitting a PDF form to a PHP script

Posted: Wed Jan 21, 2009 3:34 pm
by rhecker
Thanks for the suggestion. If I understand you correctly, the FDF file on the server would then be overwritten by each site visitor who fills out the form. If there is a way to tell the FDF file to replicate itself with a new, randomly generated name, I certainly don't know how. So your suggestion leaves me with essentially the same problem, but relying on a technology (FDF) which I understand less.

Going back to the method I was really looking for a solution to, the hurdle for me is knowing how to use PHP to upload the FDF or PDF generated when a user fills out a form and store it on the server with a generated name.

Thanks

Re: Submitting a PDF form to a PHP script

Posted: Wed Jan 21, 2009 3:40 pm
by Burrito
creating a unique file name for each .fdf. That's as easy as appending a new database row, or simply incrementing a number in a flat-file.

I suggested this as a solution because it's exactly the way I do it and it works perfectly.

Re: Submitting a PDF form to a PHP script

Posted: Wed Jan 21, 2009 4:56 pm
by rhecker
Glad to hear you have done this. Then it would be great to see the code. As I've said, I'm not familiar with how to script an FDF.

Thanks

Re: Submitting a PDF form to a PHP script

Posted: Wed Jan 21, 2009 5:10 pm
by Burrito
basically you need export the form data to an fdf from Acrobat. Then open the .fdf with any text editor and replace the values with variables.

it will look something like this:

Code: Select all

 
%FDF-1.2
%âãÏÓ
1 0 obj
<< 
/FDF << /Fields [ << /V /Yes /T (check1)>> << /V /Yes /T (check10)>> << /V /Yes /T (check11)>> 
<< /V /Yes /T (check12)>> << /V /No /T (check13)>> << /V /Yes /T (check14)>> 
<< /V /No /T (check15)>> << /V /No /T (check16)>> << /V /No /T (check17)>> 
<< /V /No /T (check2)>> << /V /Yes /T (check3)>> << /V /Yes /T (check4)>> 
<< /V /Yes /T (check5)>> << /V /Yes /T (check6)>> << /V /Yes /T (check7)>> 
<< /V /Yes /T (check8)>> << /V /No /T (check9)>> << /V (Some Name Value)/T (name)>> 
<< /V (Some Address Value)/T (Address)>> << /V (Some City Value)/T (City)>> 
] 
/F (mypdf.pdf)/ID [ <ed9cd76cd4343ssd4323848a8f71aa5c43><53b6df343dsfds34lj9343234346af85>
] >> 
>> 
endobj
trailer
<<
/Root 1 0 R 
 
>>
%%EOF
 
The way I do it (to cut down on time), is to just enter my values as the PHP variable that they're going to take. EX: $_POST['name'] for the name field in the PDF. Then when you export it, everything (in the case of text fields) is already in place and ready to go.

After you've set up your .fdf the way you want it, you just create it as one long string variable then write it out to a file with a unique name (using one of the two methods I mentioned above). At the end of the fdf where it has the pdf's name: mypdf.pdf in the case above, you just replace that with the FQDN of the pdf on the server EX: http://www.mysite.com/mypdf.pdf.

After you've saved the file as an .fdf, just use a header() to send the user to the location of the fdf and it will open the pdf referenced in the fdf with this form information.