Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can FPDF/FPDI use a PDF in landscape format as a template?

Tags:

php

fpdf

fpdi

I am trying to import an existing PDF as a template with FPDI. The template is in landscape format. If I import the template into a new document the template page is inserted in portrait form with the content rotated 90 degrees. If my new document is in portrait the full content appears, but if the new document is also landscape, the content is cropped.

Is it possible to use a landscape template with FPDI?

like image 748
Jim OHalloran Avatar asked Nov 18 '08 05:11

Jim OHalloran


1 Answers

sure, it is no problem. Just add "L" as parameter when calling "addPage()". Here is a sample which works fine for me (the template is in landscape)

<?php
require_once('fpdf.php');
require_once('fpdi.php');

$pdf =& new FPDI();
$pdf->addPage('L');
$pagecount = $pdf->setSourceFile('template.pdf');
$tplIdx = $pdf->importPage(1); 
$pdf->useTemplate($tplIdx); 
$pdf->SetFont('Arial'); 
$pdf->SetTextColor(255,0,0); 
$pdf->SetXY(25, 25); 
$pdf->Write(0, "This is just a test"); 
$pdf->Output('newpdf.pdf', 'F');

?>
like image 149
crono Avatar answered Sep 30 '22 02:09

crono