Automatically printing PDF prints OK but throws error in Adobe Reader (TCPDF)

Posted on 2008-11-03
Last Modified: 2012-05-05
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(){


		// Include print dialog opening JavaScript



		// Create a page with some content



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

Question by:absx
    LVL 19

    Expert Comment

    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.
    LVL 19

    Expert Comment

    Also, can I ask you something, why are you doing:


    Instead of:


    I'm curious..

    LVL 9

    Author Comment

    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.
    LVL 19

    Assisted Solution

    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.

    LVL 9

    Accepted Solution

    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.
    LVL 19

    Expert Comment

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


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now