Are there any specific functions or methods in FPDF for rotating PDF files?
To rotate a PDF file using FPDF, you can use the `Rotate()` method provided by the library. This method allows you to rotate the current page in the PDF document by a specified angle. By using this method, you can easily rotate the pages in your PDF file to the desired orientation.
require('fpdf.php');
class PDF extends FPDF {
function Rotate($angle,$x=-1,$y=-1) {
if($x == -1)
$x = $this->x;
if($y == -1)
$y = $this->y;
if($this->angle != 0)
$this->_out('Q');
$this->angle = $angle;
if($angle != 0) {
$angle *= M_PI/180;
$c = cos($angle);
$s = sin($angle);
$cx = $x*$this->k;
$cy = ($this->h-$y)*$this->k;
$this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
}
}
function _endpage() {
if($this->angle != 0) {
$this->angle = 0;
$this->_out('Q');
}
parent::_endpage();
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Rotate(90);
$pdf->Cell(40,10,'Rotated!');
$pdf->Output();