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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

BrianGEFF719Commented:
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
absxAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.