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.
<?
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();
?>

Open in new window

test.pdf
LVL 9
absxAsked:
Who is Participating?
 
absxConnect With a Mentor Author Commented:
Thank you BrianGEFF719,

This helps, but doesn't solve the original problem. I'm falling back to letting the users click the print button themselves.
0
 
BrianGEFF719Commented:
The file you've uploaded works fine for me...It loads right up and begins the print process.

Try upgrading your version of Acrobat, I'm using the latest version.
0
 
BrianGEFF719Commented:
Also, can I ask you something, why are you doing:

   TCPDF::__construct();

Instead of:

  parent::__construct();

I'm curious..

Brian
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
absxAuthor Commented:
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.
0
 
BrianGEFF719Connect With a Mentor Commented:
Hi Absx,
I'm using Acrobat Reader 9, I open the file it opens the print dialog window, I print and it completes with absolutely no error.

Brian
0
 
BrianGEFF719Commented:
>>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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.