April 23, 201016 yr Ok, so I assume that this is fairly simple but I don't have enough programming experience to get it to work correctly. I have a html form that I have made to generate a fdf file and save it on the server. This file should then be opened using a pdf also on the server and insert the form details into the correct part of the pdf. It works fine but not in one simple step. I need to add something to my php such that when the form is submitted, the fdf file is saved and then immediately opened and displayed to the user. As it currently stands, the file needs opening manually. I've been messing about with fdf_open but without success!? <?php // check that a form was submitted if(isset($_POST) && is_array($_POST) && count($_POST)){ // we will use this array to pass to the createFDF function $data=array(); if(isset($_POST['Text2'])){ // the name field was submitted $pat='`[^a-z0-9\s]+$`i'; if(empty($_POST['Text2']) || preg_match($pat,$_POST['Text2'])){ // no value was submitted or something other than a // number, letter or space was included die('Invalid input for Text2 field.'); }else{ $data['Text2']=$_POST['Text2']; } if(!isset($_POST['Text3'])){ die('You did not submit the correct form.'); } $data['Text3']=$_POST['Text3']; $data['Text4']=$_POST['Text4']; $data['Text5']=$_POST['Text5']; // Date $data['Text1']=date('d/m/Y'); // FDF file - function definition require_once 'createFDF.php'; // file name .fdf $fdf_file=$_POST['Text2'].time().'.fdf'; // the directory to write the result in $fdf_dir=dirname(__FILE__).'/results'; // pdf file for data to go into $pdf_doc='../voucher_online.pdf'; // generate the file content $fdf_data=createFDF($pdf_doc,$data); } }else{ echo 'You did not submit a form.'; } ?>
April 23, 201016 yr If I've understood correctly, you cannot do what you want - that is to say, you cannot return the PDF data to the client (so it loads automatically in the browser) and then tell the PDF viewer to load the FDF data into the displayed document (this last action is a manual one). Instead you'll need to look at a solution which can put the FDF data into the PDF on the server, and save the result as a regular PDF which can then be returned as the response to the client. Of course they won't be able to edit the data in the PDF, but that shouldn't be a problem for you (otherwise why not just stick with HTML forms?). This process is usually called "merging" or "flattening" the PDF template+form into a single uneditable PDF document. Try a Google search for "pdf fdf flatten" and "pdf fdf merge" to see the available toolkits. There may not be a PHP-native way to do this however.
April 23, 201016 yr Author now that would explain why I could not for the life of me make it work! Thanks, I will have a look and inevitably come crawling back to the forum in a couple of hours!
April 24, 201016 yr I agree, have the file saved as a PDF file, then do something like this to display it in the browser: <?php header('Content-type: application/pdf'); header('Content-Disposition:inline; filename="original.pdf"'); readfile('original.pdf'); ?> Or have the user download the PDF: <?php header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="original.pdf"'); readfile('original.pdf'); ?> You will probably need to edit the above to work but that's I think along the lines of what you need to do (it's a saturday morning so my mind is still half asleep)!
April 24, 201016 yr Author Yeah that works perfectly for opening the file, now I just need to find a way of turning my fdf into a pdf. Not had much success in making sense of anything I have found thus far. Thanks for that tho....another step closer! :-)
Create an account or sign in to comment