Please keep in mind that it is not exactly a .PDF document, it is a FDF file that calls a PDF on it's own The readfile(name.fdf) will thus bring up a linked PDF file. You do not open the PDF directly (it is blank) Got that
The FDF and PDF file are working just fine my problem is how do I display it when the script runs...
I had some success with:
Code: Select all
header("Location: http://localhost/QSL/results/$fdf_file");
header('Content-type: application/pdf');
exit;
But it would open IE to show the file if I was using FF...
This is the code that will pull users info from the DB and make the FDF file. (makepdf.php)
Code: Select all
// db connect info, other functions not used by this file
include('includes/config.php');
// this will be removed, used for testin with no form
$contact_id = "2";
// check that data was submitted
if(isset($contact_id)) {
// get the log informatiuon from the db
$results = mysql_query("SELECT * FROM contacts WHERE id = $contact_id ") or die (mysql_error());
// check to make sure that only one record is found for the contact_id requested
$numrows = mysql_num_rows($results);
if($numrows != '1') {
echo "ERRORO - No or Mutiple records found for your request, please contact our system admin.";
die;
}
// set up array to hold form data
$data=array();
// put db data into array
while ($mysql = mysql_fetch_array($results)) {
$data['callsign'] = $mysql['callsign'];
$data['callsignname'] = ''.$mysql['callsign'].' - '.$mysql['name'].'';
$data['namecallsign'] = ''.$mysql['name'].' - '.$mysql['callsign'].'';
$data['datetime'] = 'Date - Time: '.$mysql['date'].' - '.$mysql['time'].'';
$data['time'] = 'Time: '.$mysql['time'].'';
$data['band'] = 'Band: '.$mysql['band'].'';
$data['freq'] = 'Frequency: '.$mysql['freq'].'';
$data['mode'] = 'Mode: '.$mysql['mode'].'';
}
// need the function definition
require_once 'createFDF.php';
// some variables to use
// file name will be <the current timestamp>.fdf
$fdf_file=$data['callsign'].'_'.time().'.fdf';
// the directory to write the result in
$fdf_dir=dirname(__FILE__).'/results';
// need to know what file the data will go into
$pdf_doc='http://localhost/QSL/100yrs.pdf';
// generate the file content
$fdf_data=createFDF($pdf_doc,$data);
// this is where you'd do any custom handling of the data
// if you wanted to put it in a database, email the
// FDF data, push ti back to the user with a header() call, etc.
// write the file out
if($fp=fopen($fdf_dir.'/'.$fdf_file,'w')){
fwrite($fp,$fdf_data,strlen($fdf_data));
// echo $fdf_file,' written successfully.';
}else{
die('Unable to create file: '.$fdf_dir.'/'.$fdf_file);
}
fclose($fp);
}else{
echo 'You did not submit a form.';
}
This is the createFDF.php
Code: Select all
/*
KOIVI HTML Form to FDF Parser for PHP (C) 2004 Justin Koivisto
Version 2.1.2
Last Modified: 9/12/2005
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Full license agreement notice can be found in the LICENSE file contained
within this distribution package.
Justin Koivisto
justin.koivisto@gmail.com
http://koivi.com
*/
/*
* createFDF
*
* Takes values submitted via an HTML form and fills in the corresponding
* fields into an FDF file for use with a PDF file with form fields.
*
* @param $file The pdf file that this form is meant for. Can be either
* a url or a file path.
* @param $info The submitted values in key/value pairs. (eg. $_POST)
* @result Returns the FDF file contents for further processing.
*/
function createFDF($file,$info){
$data="%FDF-1.2\n%âãÏÓ\n1 0 obj\n<< \n/FDF << /Fields [ ";
foreach($info as $field => $val){
if(is_array($val)){
$data.='<</T('.$field.')/V[';
foreach($val as $opt)
$data.='('.trim($opt).')';
$data.=']>>';
}else{
$data.='<</T('.$field.')/V('.trim($val).')>>';
}
}
$data.="] \n/F (".$file.") /ID [ <".md5(time()).">\n] >>".
" \n>> \nendobj\ntrailer\n".
"<<\n/Root 1 0 R \n\n>>\n%%EOF\n";
return $data;
}