LatentDenis
LatentDenis

Reputation: 2991

How do you force FPDF Output to be exactly 11 in. by 8.5 in?

What setting would I need to change and to what in order for the rendered PDF file to be exactly 11 in. by 8.5 in.? Right now, for some reason the PDF I generate is 11.69 in. by 8.27 in. .

The code above is the only thing that works at producing a PDF, I've tried "new FPDF" instead of "new FPDI" and all I get are errors. How can I alter this code to be 11x8.5?

<?php
ob_clean();
ini_set("session.auto_start", 0);
define('FPDF_FONTPATH','font/');
define('FPDI_FONTPATH','font/');
require('fpdf.php');
require('fpdi.php');
$pdf = new FPDI();
$pdf->setSourceFile("Flyer.pdf");
$tplIdx = $pdf->importPage(1);
$specs = $pdf->getTemplateSize($tplIdx);
$pdf->addPage($specs['h'] > $specs['w'] ? 'P' : 'L');
$pdf->useTemplate($tplIdx,  0, 0, 297, 210);
$pdf->SetFont('helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');
ob_end_clean();
$pdf->Output('marketing.pdf', 'F');
?>

Upvotes: 0

Views: 785

Answers (1)

Eugene
Eugene

Reputation: 2878

11.69 x 8.27 inches is A4 size used by default by FPDF (the documentation says: Default value is A4.)

11 x 8.5 inches is the Letter paper size so you should just set it as a parameter for the constructor:

$pdf = new FPDF('P','inch','Letter');

Upvotes: 2

Related Questions