Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read pdf (The file is damaged and could not be repaired)

Status
Not open for further replies.

lonelydragon

Programmer
Aug 5, 2004
75
US
hello, all:
i have the following code trying read a pdf file and updated it. but i always ge the error "The file is damaged and could not be repaired". thank you for help.
<?php
header( 'Content-type: application/pdf' );
header( 'Content-Disposition: filename=cert.pdf');

$fileName = 'webCertificate.pdf';
$fp = fopen ($fileName, 'r' );

//read our template into a variable
$outputs = fread($fp, filesize($fileName));
fclose ($fp);
$studentName = "Mary Lee";
$courseCocName = "Information Science";
$completionDate = "May 12,2005";
$certNumber = "2005"; $outputs = pdf_replace("<<studentName>>", "rongke", $outputs);
print $outputs;

function pdf_replace($pattern,$replacement,$string) {
$len = strlen($pattern);
$regexp = '';
for ($i = 0; $i<$len; $i++ ){
$regexp .= $pattern[$i];
if ($i<$len-1)$regexp .= "(\)\-{0,1}[0-9]*\(){0,1}";
}


return ereg_replace($regexp,$replacement,$string);
}

?>
 
I would advise to get the FDF toolkit (if you can install on the server) and use a PDF template that has actual dynamic fields and fill in the FDF data on the fly.
A text based search and replace will (as your example shows) not work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top