absx
asked on
Automatically printing PDF prints OK but throws error in Adobe Reader (TCPDF)
Hi experts,
I've been working on a web application that occasionally generates PDF printouts. For convenience the print dialog is opened automatically with a "print();" JavaScript command that's included in the PDF file. The PDF file gets generated fine, looks all right, prints straight, but for some reason the Adobe Reader (both desktop app and plugin) gives the error message "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem" after printing. Foxit Reader prints the file without displaying error messages, but shows a informational message stating "This document contains interactive form fields".
I'm using the TCPDF library, as it's the only one I found that supports attaching JS. I've attached example code - a bare minimum that generates an A4 page with a single string of text which still gives the error message after printing. An example PDF file generated by this script is also attached.
I've some experience in generating PDF files using bundled libraries, but little in the actual syntax of PDF.
I've been working on a web application that occasionally generates PDF printouts. For convenience the print dialog is opened automatically with a "print();" JavaScript command that's included in the PDF file. The PDF file gets generated fine, looks all right, prints straight, but for some reason the Adobe Reader (both desktop app and plugin) gives the error message "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem" after printing. Foxit Reader prints the file without displaying error messages, but shows a informational message stating "This document contains interactive form fields".
I'm using the TCPDF library, as it's the only one I found that supports attaching JS. I've attached example code - a bare minimum that generates an A4 page with a single string of text which still gives the error message after printing. An example PDF file generated by this script is also attached.
I've some experience in generating PDF files using bundled libraries, but little in the actual syntax of PDF.
<?
require_once('tcpdf.php'); // Version 4.2.001, 2008-10-30
class test extends TCPDF {
public function __construct(){
TCPDF::__construct();
// Include print dialog opening JavaScript
$this->setUserRights();
$this->IncludeJS("print();");
// Create a page with some content
$this->AddPage();
$this->Cell(0,0,"Testing",0,1,'L');
// Stream file
$this->Output("test.pdf", "I");
}
//Page header, overrides TCPDF default
public function Header() {
}
//Page footer, overrides TCPDF default
public function Footer() {
}
}
$foo = new test();
?>
test.pdf
Also, can I ask you something, why are you doing:
TCPDF::__construct();
Instead of:
parent::__construct();
I'm curious..
Brian
TCPDF::__construct();
Instead of:
parent::__construct();
I'm curious..
Brian
ASKER
Hi BrianGEFF719,
The full class name is used simply for I wasn't aware of the parent:: syntax. Did you actually print the document from the dialog? The problem is, that the dialog opens and the file prints, but there's an error message afterwards. If 'cancel' is clicked in the dialog, no error gets displayed, either.
I'm using Adobe Reader version 8.1.2. and my users are unfortunately unable to upgrade their Reader versions because of corporate policies so I'd prefer generating as compatible PDF as possible.
The full class name is used simply for I wasn't aware of the parent:: syntax. Did you actually print the document from the dialog? The problem is, that the dialog opens and the file prints, but there's an error message afterwards. If 'cancel' is clicked in the dialog, no error gets displayed, either.
I'm using Adobe Reader version 8.1.2. and my users are unfortunately unable to upgrade their Reader versions because of corporate policies so I'd prefer generating as compatible PDF as possible.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>I'm falling back to letting the users click the print button themselves.
It doesn't sound like you have any other option.
Best of luck.
Brian
It doesn't sound like you have any other option.
Best of luck.
Brian
Try upgrading your version of Acrobat, I'm using the latest version.