How to send PDF data to SQL database on clicking a submit button

Hi. This is my situation.

I have 1000 customers. Each of them have their own customer ID. I want to send a pdf to everyone with 5 questions, and once they submit the form, ideally the data comes straight to my SQL database. I also want to track who's who, so I want to send the customer ID to the PDF form with the link I send to my customers.

Not sure how to do it, tried sending the ID through GET method, so its then Managed to read the ID and put it into a text field in the PDF form, but it doesn't work on Chrome browser just on mozilla and IE.

So I would like to know another method to send the ID to the PDF first, and then once the customer fills the form and submits it, the ID and answers to the questions come to my database. What's the best way to do this or other solutions to achieve the same thing?
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.

Karl Heinz KremerCommented:
Chrome has it's own PDF viewer built in, the other browsers use Adobe Reader (or Acrobat if installed). The built-in viewer behaves quite a bit differently than Reader.

I would send a FDF file instead of the PDF file, and let the FDF file load the PDF file from the server. The FDF file can contain the user ID, so you don't have to do any tricks to get that information into the form. Once you submit the form, submit it just like a regular HTML form (that's one of the options when creating the submit button), and then let your server handle the communication with the SQL server.

Have you ever worked with FDF files before. Do you know what an FDF file is?
Eddie ShipmanAll-around developerCommented:
What is your server-side development language?
Eddie ShipmanAll-around developerCommented:
To be honest, this is better left to HTML forms and not using PDF to do this.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Karl Heinz KremerCommented:
There is nothing wrong with PDF forms for this application. If it's important that the form's design is the same as e.g. a printed form, or for other form fidelity reasons, you can do whatever you could with HTML forms also with PDF forms.
Eddie ShipmanAll-around developerCommented:
If It's just 5 questions, don't you think the PDF is a little overkill?
Eddie ShipmanAll-around developerCommented:
If he's using ASP, then this article shows a great way to do this with PDF:

The FDF toolkit is really not needed except to build the FDF and you can use Acrobat to do that.

I've done this in ASP and PHP.
Karl Heinz KremerCommented:
We don't know what else is on the form, so I go with the asker's plan to use PDF.
You are right, the FDFtoolkit is not needed - it's very easy to create the contents of a FDF file with any web technology.
Tomas Helgi JohannssonCommented:

If your website is building the pdf files on the fly then its easy to put
the ID into a query-string and use it to build a form that holds the customer ID.
This can be done either with HTML forms or PDF or matter of fact any web language.
The only thing you have to have in mind how the workflow is in your case.

Let's say you are sending each customer a link to this webpage that builds your question form. Then you need to provide the url the customerid something like this 
and then you pass the custid parameter and value to your form and then use that along with the answers and insert the data to required tables.

    Tomas Helgi
udara22Author Commented:
Hello everyone, thanks a lot for the advices.

The company wants to give the staff members the ability to create forms so it takes the work load from web developers, and PDFs can be downloaded, and filled at a later stage and submitted once done. If the PDF data collecting works fine, the company might use this technology for all their forms (some of them are big). Thats the reason for using PDFs. I suggested HTML forms too, but they are really keen to use this technology.

I tried passing the I'd through the url, it works on Mozilla and ie, but not in chrome, for some reason in chrome it says "Undefined". And on mac it pops up the 'save to location' popup so cannot pass through URL

I haven't worked with PDFs before. Very new to me. I thought of using ajax to post the data to server, I put the below code in the "button's" javascript (I got this from the internet)

    type : 'POST',
    url : '',
    dataType : 'json',
    data: {
        "questionone" : this.getField("questionone").value
    success : function(data){

    error : function(XMLHttpRequest, textStatus, errorThrown) {

and put this in the process.php file

$questionone= $_POST['questionone'];
$to = "";
$subject = "Test mail";
$message = $questionone;
$from = "";
$headers = "From:" . $from;
echo "Mail Sent.";

I thought this might send me and email once the data goes to the process.php file. But I didn't receive and email with $questionone.

I have a feeeling just ajax post might do the trick, but really cant get it to work and driving me nuts. Is there anything wrong with the ajax code or whats the best way to test it from the process.php page?
Eddie ShipmanAll-around developerCommented:
I can work up something based on the 15seconds article tonight, including sending the UID.
Karl Heinz KremerCommented:
Here is a small problem with your idea: If your clients/customers/employees do not all have the full version of Acrobat (not the free Reader), you will have a problem - PDF forms cannot be saved by Reader in a half filled state and later submitted. If you do have the user ID in the PDF file as ThomasHelgi suggested, this may not be a problem, but if you are planning on sending the ID via a FDF file, you are partially filling the form with the ID, and then the user would have to fill the complete form in that session.

There are ways around that: You can reader-enable your document, and give it more rights when it gets opened in Reader. Saving a form is one of the options. You can use Acrobat to create such forms, but the EULA you accepted when you installed Acrobat limits you to 500 forms (either sent out or received), so your 1000 customers would fall well outside that limit. You can also use a server based solution to reader enable those forms, but that has a much higher price tag than Acrobat. You need to talk to somebody at Adobe to find out exactly how much that server solution would cost for your application.
Eddie ShipmanAll-around developerCommented:
No, No, No. read the article I posted. By using the FDF, they aren't actually "saving" the form data but going to be sending tit to the corresponding script that takes the values and saves them to DB.
udara22Author Commented:
@EddieShipman : Thanks for the link Eddie, I had a good look, but unfortunately I am using php and my asp skills are nil. Also my server side development language is PHP. I've seen the technique of using CGI-BIN to pass the information, but not sure how it really works  and my server doesn't have a cgi-bin folder? Also eddy is it possible to use the link you send on a php server?

@khkremer : I tried saving the form in Reader and it works fine. Also in regards to the adobe form limit; I though this limit wont affect the form at all if I put a javascript submit button to submit the forms, not the submit button you see at the top of the Acrobat Toolbar?

@EddieShipman and khkremer : Can you guys please explain how the FDF works? In the worst case, I might get the customers to put the customer_id manually, maybe put the customer id in the email and ask them to copy and paste, not the ideal solution, but I have no idea how the FDF solution can be integrated on to this form and pass the customer Id.Passing the id through the url was an amazing, easy solution, but blooyd chrome doesn't like it.  I won't be able to generate the PDF on the fly because the company wants the staff to create the form and me to put the javascript codes on to the PDF so it interacts with the external PHP file on my server and the PHP file writes the data to the SQL database..
Karl Heinz KremerCommented:
The 500 copy limit only applies when you reader-enable the form, e.g. so that you can save the form locally with the form data. Without reader-enabling a form, you can still save the form in Reader, but it will only save the blank form. So if you can create your form without the need to reader-enable it, then the limit does not come into play. However, it does not matter if you use the submit button at the top of the window, or your own button that calls the Javascript submit function, or any other way you can think off. Technically, even printing such a file and sending in the printout would probably count as submission.

The problem is that if the user ID is provided via the FDF file (which stands for forms data file), then the form is partially filled (with the user ID), and when you then save it in Reader, it will not save that information, you will end up with a blank form again.

You can create your own FDF sample file in Acrobat. Just load your form, fill in some information and then save the form data. How you do that depends on which version of Acrobat you are running. In Acrobat X you'll find this on the Tools pane at Forms>More Forms Options>Manage Form Data>Export. I'll try to whip something up to demonstrate what FDF files can do.
Karl Heinz KremerCommented:
Go to and see what happens - you should get a form with some data filled in. You can see both the forma and the FDF file when you select the directory

The submit button is not doing anything in this sample, but you can take the two files, change the two instances of the URL in the FDF file and try it on your own server.
udara22Author Commented:
Hi khkremer, Thank you very much for your time. It worked fine on mozilla (pc) but not on chrome(pc) and mozilla and chrome(mac). Also can you tell me how to grab the code in the fdf?
udara22Author Commented:
@khkremer : also when i open on mac firefox, it asked me to save the fdf and didnt really direct me to pdf with the id in it?
udara22Author Commented:
Guys, I used FPDF to generate the pdf and added the id through a GET variable and passed the ID through the URL. Now, it grabs the ID on any browser and generates the PDF with the ID in it, which is awesome. So i might use fpdf to solve the ID issue, ;

But now the issue is , is it possible to chuck my existing pre-designed pdf with input fields in to this fpdf process so it has all the fields + the customer ID?
Eddie ShipmanAll-around developerCommented:
The way it works in the article is you have your PDF already designed with the form fields. Then you create an FDF to match the form fields. I was not able to work on the demo last night but will try to get to it today or this evening..

Now, you can pass the ID into the script that creates the FDF and have it pre-populate a field in the PDF with the CustomerID, I'll put that in the demo.
Karl Heinz KremerCommented:
As I said, chrome has it's own PDF viewer and will always be a problem. You have to turn off it's viewer via about:plugins. I don't know about the Firefox problems. It's supposed to work...

I don't think that FPDF allows you to merge existing PDF files.

You could merge the FDF and the PDF on the server. A simple and free tool to do that is pdftk ( This way, the PDF is already prefilled, and you avoid the problems that a downloaded FDF would have.
Eddie ShipmanAll-around developerCommented:
Ok, I've been working on this for a while and can't get the form to pre-populate nor submit.
I did, however, find a great tutorial on this subject that you may be interested in:

Check it out and see if it helps you.
udara22Author Commented:
@khkremer : Yes FPDF needs FPDI to merge existing PDFs and it's merged as an image so I lose the input fields. So I guess FPDF isnt the way to go with this.

@EddieShipman : Eddie, Thanks heaps, tutorial looks like a real deal, I guess I just need to reverse the process from HTML - > PDF to PDF -> HTML. Not easy but i'll give it a go.

@khkremer and EddieShipman : I also found this article, will sit down and read it now, what do you guys this about this?
Eddie ShipmanAll-around developerCommented:
The problem I ran into is that the browsers would not serve the PDF, that the FDF referenced, from the web. I can go ahead and post the code converted from ASP to PHP and you can play with it to see if you can get it working.
Karl Heinz KremerCommented:
Take a look at pdftk - it will be very easy to merge a PDF file with data from an FDF file.

The article you are referencing is based on Adobe's FDFToolkit, which is very old, and you may have problems getting it running on a modern system. As I said before, there is no need to use the FDFToolkit to create an FDF file. It's just a text file, and all you need to do is make sure that you don't get the opening and closing marks messed up :)

Download the FDF from my server and take a look, it's pretty simple. You can add spaces and linefeeds to make it look nicer - as long as you don't add anything inside the "<<" or ">>" or between the "/" and the following command name. So, this would be OK:

1 0 obj



<</Root 1 0 R>>


Open in new window

To add more fields, just add more /T /V pairs. The /F and /UF values point to the PDF file on the server, but when you merge via pdftk, these values get ignored. Give it a try, just take a PDF file, construct a FDF file (you can even export one from Acrobat and then modify it - that's what I usually do), and then use pdftk to merge e.g. the user ID into your PDF. Do this on your desktop to get some experience, and then try to do it on the server before you download the PDF file to the user.
Eddie ShipmanAll-around developerCommented:
Attached is the code from the 15seconds article converted to PHP. I can't get it to pre-populate the fields nor submit to the FormTestSubmit script. The URL in the Action on the button is correct but it may be that this is an old PDF and the reader is having problems with it. I will try to remake the PDF in Acrobat9 and see if it works.

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
udara22Author Commented:
Sorry guys, couldn't reply, got the bloody winter flue..

@khkremer,  Thanks heaps, then I wont go ahead with that old article. Again, I made the FDF right, and pdftk looks good too, but I'm wondering how pdftk works on the server because its an .exe file? Sorry if I sound stupid, but what am I doing wrong?

So, If i need to pass the UserID to the PDF file, should I pass it through FDF file ? if so how can that be done, do I need to create new FDF file per customer?

Also, would you mind having a look at EddieShipmans ZIP file, it looks pretty damn close but having trouble with passing and importing data. :)

@EddieShipman, Thanks a lot man. I think we are almost there, which is awesome.

Few things tho,

[1]. I figured out why importing data doesn't work. When the PDF opens up, at the top it has a button called "Options", If you click on it , is gives 2 options; 1. Trust this document, 2. Block this document. If you click Trust this Document, it populates the fields, otherwise it doesn't. But customers might miss this step like we did, then it wont grab the customer ID, which might be a problem.

[2]. Also if I open the FormTestImport.php?UserID=123 on chrome, it downloads the FDF file and nothing happens from there. :(

[3] For receiving UserID, I think GET is the way to go as we have at the moment so  I can pass the id through the URL, and what if we use "POST" for passing the other information to the FormTestSubmit.php file? Because some user input data might be very long to pass through the URL. I tried changing to POST, but no luck.

If we can pass the POST data to FormTestSubmit.php, we are almost there. Not sure why posting data doesn't work.What if we use ajax on the submit button to POST to the URL instead of the 'Submit Form' action? I tried using ajax too, didnt work. Maybe I missed something because PDF APIs are different to standard javascript. :S
udara22Author Commented:
EUREKAAA... Alright lets cool down here. I managed to pass the data from PDF to FormTestSubmit.php. Its so simple, what we have to do is, just put the code below on to the top of the FormTestSubmit.php and it shows the array of data we receive from the PDF file.

 echo '<pre>'; print_r($_POST); echo '</pre><br><br>'; 

Open in new window

and in the table cell, it should look like this

<? echo  $strFirstName ?>

Open in new window

Now, I can receive the user input data, and can be written to a database. Which is awesome. The only issue is passing the UserID to the pdf. PHP to FDF to PDF doesnt work on Chrome and also on MAC. Can you guys think of a way around it? The worst case I might get the user to input the UserID too, but it might be a security and reliability issue and my boss wont like it either.. :S
Eddie ShipmanAll-around developerCommented:
One thing you could do is have a HIDDEN field in the PDF, and thus the FDF that gets populated by from the script. Pass it in the URL and populate it in the FormTestImport script.
It would also then be available in the FormTestSubmit script just as another form field.

You can tell Chrome to use Adobe's reader:
1. Install Adobe Reader or Adobe Acrobat if it is not already installed
2. Open Google Chrome
3. In the address bar, type . . .
      about:plugins (that’s the word about  a colon (:), then plugins
4. The Plug-ins Tab will open
5. Scroll down until you see either Adobe Acrobat or Reader.
6. Click the Enable link

You will need to notify the users of Chrome that they have to do that to be able to fill your form.
Karl Heinz KremerCommented:
You should be able to call the .exe file from your PHP script. If you don't want to figure out how, you may want to take a look at the pdftk-php project:
It creates a FDF file on the fly, calls pdftk and outputs the resulting PDF file to the browser. All you need to do is change the path to pdftk and the options it uses to merge the FDF and PDF (it also flattens the file, which you don't want to do, because it strips all other interactive form fields from your PDF).

... or you could just use the source of pdftk-php as a model for your own implementation.
udara22Author Commented:
Thanks eddy.  Yes, that's what I tried doing, pass the id through url to FormImportTest.php and populate the PDF. But it doeant work on mac. Mac browsers just download the fdf and nothing happends after that.
Eddie ShipmanAll-around developerCommented:
But if you make the UserID part of the PDF/FDF as a form field that is not visible, you should be able to parse it into the FDF using PHP just like any other field in the FormTestImport script.

Do any of the PDF fields get populated on the Mac?
udara22Author Commented:
@khkremer : thanks. I'll try it and let you know how it goes.

@eddyshipman : eddy, if the hidden field gets populated with out any user interactivity, that's all I need. Let's see. I'll try it when I get to the office in 1 hour.

Then what I might do is, force the PDF download so no browsers can affect PDF. I wondering whether the hidden field value will be there when the users download the pdf.?
Eddie ShipmanAll-around developerCommented:
None of the form fields will save data when PDF is saved.
udara22Author Commented:
@khkremer : Thanks for the pdftk-php link. Im getting there with it. But one problem, I'm not sure how to link the PDF Tool kit downloaded files with pdftk-php.php on line 71. I downloaded PDF tool kit files and put the files on to a folder on the server, and I put the absolute path to that folder, but it throws an error when I try to see the submitted PDFs

passthru("C:\Users\udara\Documents\My Web Sites\test Server\pdfdata\orig_pdftk $pdf_original fill_form $fdf_fn output - flatten");

Open in new window

Should I just drag and drop the files from the PDF Tool kit to orig_pdftk folder? My Folder path looks like this now

-- bin
-- docs
-- license_gpl_pdftk

is this correct?
udara22Author Commented:
@EddieShipman : I tried passing data to the hidden field, it still gets blocked by acrobat and asks for user permission to populate the data, so by the looks of it we can't pass the UserID through the URL using FormTestImport.php. And also on mac its crazy, it just opens the FDF file and sometimes the PHP file with the FDF data in it.
Eddie ShipmanAll-around developerCommented:
Can you post your new code and PD?
Karl Heinz KremerCommented:
That's a problem with the "\" characters, which are interpreted by PHP as escape characters - in order to get "real" backslashes, you need to escape them with a backslash... So try something like this in the passthru command:
passthru("C:\\Users\\udara\\Documents\\My Web Sites\\test Server\\pdfdata\\orig_pdftk $pdf_original fill_form $fdf_fn output - flatten");

Open in new window

udara22Author Commented:
@khkremer : I changed the path \ to \\, but same error. I recon its the place I've put the pdfToolKit files are wrong. Coz the path looks correct.

@EddieShipman : See attached file. I removed everything else from the FDF section on the FormTestImport.php and just left the UserID so you can test. Again, if i "allow", the UserID goes through to the submit page, if not, it doesn't.
Karl Heinz KremerCommented:
I just tried this on a Windows machine, and the "\\" as path delimiter works. Are you sure you installed pdftk correctly? There are two files that need to go into the same directory (the executable and a library). What is the error you are getting? Try to just have the path to pdftk.exe in the passthu call (without any arguments). Does that work?
udara22Author Commented:
@khkremer and EddieShipman : Guys, after a lot of trial and error I came to a solution. Letting customer copy and paste the client id form the Email they receive. So I though I might make the ClientID field required and put it as a standard input field.

Now everything looks fine. thanks guys a lot for your help and I really appreciate your help on this.
udara22Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for udara22's comment #37784659
Assisted answer: 200 points for khkremer's comment #37752827
Assisted answer: 300 points for EddieShipman's comment #37766451

for the following reason:

Thanks guys a lot.
Eddie ShipmanAll-around developerCommented:
You could hwve closed and assigned the points yourself. Just select accept multiple solutions.
udara22Author Commented:
Ah cmon. You guys deserve it for the time you put in for this.
Eddie ShipmanAll-around developerCommented:
I know that, but I was saying that you disn't have to enter a close request but to accept the solutions, yourself. I will get a moderator to decline the close and that will let you do it.
udara22Author Commented:
Oh. Damn. So close request doest mean the problem has been solved? This is confusing. But I selected multiple solutiins
Eddie ShipmanAll-around developerCommented:
Yes, you can select the multiples, but if you mark yours as the solution vs. assisted, it makes it a close request.
udara22Author Commented:
Hi, Please ignore the close request. I've done it by a mistake.
udara22Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 300 points for EddieShipman's comment #37766451
Assisted answer: 200 points for khkremer's comment #37766131
Assisted answer: 0 points for udara22's comment #37784659

for the following reason:

The attached file is a modified version of what EddieShipman posted, and my version works better. Thats it.
udara22Author Commented:
udara22Author Commented:
Guys, so sorry to come back to this post, but the boss didnt like to get the user to input the ID, then i found this link which uses PDFToolKit like khkremer said.

PDF array

This Works GREAT, and works on all the platforms and all the browsers. The only problem is when I use my PDF it says "FPDF-Merge Error: Incremental updates are not supported", I have no idea how to solve this issue, is there a setting in PDF at all? or a Mod i can download form the internet? Please help guys,
udara22Author Commented:
Holy shit. Figured it out.. and Thanks khkramer. PDFToolKit did the job :D
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
Adobe Acrobat

From novice to tech pro — start learning today.