TCPDF Page Rotation

I am trying to create a PDF file containing tags with a width of 202 mm and a width of 50 mm. I managed to do this and added the required text and barcode, but the problem is that the labels first print a narrow edge, so the whole page should rotate 90 degrees.

I can do this in Adobe Reader with ease by simply right-clicking on the page and selecting Rotate Clockwise (Shift + Ctrl ++), but I really need to do this in code.

Does anyone know how to do this using TCPDF? I tried the Rotate function, but could not get it to work. Any code examples would be helpful.

+7
source share
4 answers

How to configure it when creating a page?

TCPDF::__construct($orientation = 'L', $ unit = 'mm', $ format = 'A4', $ unicode = true, $ encoding = 'UTF-8', $ diskcache = false) 

$ orientation orientation (string). Possible values ​​(case insensitive):

  • P or portrait (default)
  • L or landscape
  • '' (empty line) for automatic orientation

http://www.tcpdf.org/doc/classTCPDF.html#a5420ac8b0726a604260780d8f4185fc1

+8
source

What I did with version 1.5

  $pdf->AddPage(); // Orientation for the first page is defined into configuration file. $pdf->writeHTML("Portrait 1"); $pdf->AddPage('L'); $pdf->writeHTML("Landscape !"); $pdf->AddPage('P'); $pdf->writeHTML("Portrait 2"); $pdf->Output(); 

And it works well.

+6
source

Rotate is odd. What the docs aren't telling you is that you first need to do StartTransform , then do Rotate , and then do StopTransform . You can make a call to StartTransform after you somehow set the X / Y position (for example, I use SetXY for the initial position of the page, and then you can call StartTransform ). So try to do:

  $this->pdfinvoice->StartTransform(); $this->pdfinvoice->Rotate(-90); 

then add your content then call

  $this->pdfinvoice->StopTransform(); 

when you are done. See how it works for you.

+4
source

The easiest option is to set the page in landscape mode "L" if that is what you need. Otherwise, if you need a page in portrait mode, but with rotated objects, you can create an XObject template and place your content there, including graphic transformations. Check out the default examples at http://www.tcpdf.org for graphic transformations and XObject templates.

0
source

All Articles