Search code examples
phppdfprintingtcpdfduplex

TCPDF, Duplex printing error - generated pages are inverted & mirrored


If I generate with TCPDF a two page pdf and print this together on one page (duplex) i will get an inverted result:

  • PDF generated page 1 is on paper page 2
  • PDF generated page 2 is on paper page 1

At paper page 1 I have the ci sign/style from the company so I need this to be the first page on paper.

In adobe reader I have possibilities to change some modifications but I got the same result. The PDF preview is right but the print result is wrong.

Of course I can change the paper physically in the printer itself, but the printer is standardized and work in other PDF files (not generated by tcpdf).

The best case would be to do this in the TCPDF php file directly, so the customer saves some time ;)

TCPDF duplex related variables

Adobe reader version 10.1.11 & 11.0.0.6


Solution

  • Following workaround will solve this problem. Set in your TCPDF php file class with this code the pdf settings:

    $preferences = array(
      'Duplex' => 'DuplexFlipLongEdge', // Simplex, DuplexFlipShortEdge, DuplexFlipLongEdge
      'PickTrayByPDFSize' => true,
      'PrintPageRange' => array(2,1),
      'NumCopies' => 1
    );
    
    $this->setViewerPreferences($preferences);
    

    With this line you will set the duplex page in pdf. The 2 pages would be printed on one page:

    'Duplex' => 'DuplexFlipLongEdge', // Simplex, DuplexFlipShortEdge, DuplexFlipLongEdge
    

    And then change the page order - print the second page first, then the first page:

    'PrintPageRange' => array(2,1),
    

    I'm know this is a workaround only so you more than two pages you have to set this manually again.

    Hope anyone helps this