• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6914
  • Last Modified:

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
0
absx
Asked:
absx
  • 4
  • 2
2 Solutions
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now