I'm using PHP to collect html form inputs and populates form fields in a PDF document. After it populates the PDF with the inputs from the front-end html form It prompts you to "open or save the created pdf file. My problem is when Acrobat tries to open the PDF document, I get an error message stating "Acrobat can't open file, it is either damaged or is not a supported file type, like it was sent as an email attachment and not decoded properly." I can save the pdf file but when I tru to open after saving it still gives me the same error.
Below is the source code for pdf_form_fill.php this is where I think the error is... I also have a forge_fpf.php file and will post if you think the problem is in it. any help would be appreciated... thanks John
<?php
require_once( 'forge_fdf.php' );
$fdf_data_strings= array();
$fdf_data_names= array();
foreach( $_POST as $key => $value ) {
// translate tildes back to periods
$fdf_data_strings[ strtr($key, '~', '.') ]= $value;
}
$fields_hidden= array();
$fields_readonly= array();
$fdf= forge_fdf( '',
$fdf_data_strings,
$fdf_data_names,
$fields_hidden,
$fields_readonly );
$fdf_fn= tempnam( '.', 'fdf' );
$fp= fopen( $fdf_fn, 'w' );
if( $fp ) {
fwrite( $fp, $fdf );
fclose( $fp );
header( 'Content-type: application/pdf' );
header( 'Content-disposition: attachment; filename=test.pdf' ); // prompt to save to disk
passthru( 'pdftk formtx.5.pdf fill_form '. $fdf_fn. ' output - flatten' );
unlink( $fdf_fn ); // delete temp file
}
else { // error
echo 'Error: unable to open temp file for writing fdf data: '. $fdf_fn;
}
?>