I'm using the following code to add a new page to my existing PDF document and save it.
require('addons/fpdf.php');
require('addons/fpdi.php');
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($orgpdfpath);
for($i = 1; $i <= $pagecount; $i++){
$pdf->addPage();
$tplidx = $pdf->importPage($i);
$pdf->useTemplate($tplidx);
}
$pdf->addPage($pdforientation);
$pdf->Image($imgpath,$pdfxaxis,$pdfyaxis,$pdfwith,$pdfheight);
$pdf->Output($orgpdfpath,'F');
It works fine if I have a document that is A4, Page 1: portrait, Page 2: portrait, Page 3: portrait, etc.
It also works if I add a landscape A4 Page. However, after I have added a landscape page and try to add a portrait, the landscape is shifted back to a portrait and the whole formatting of the document breaks.
I suspect that this has to do something with addPage() inside the loop. Why does does it not rotate appropriately when applying ->useTemplate?
php require('fpdf. php'); $pdf = new FPDF('P','mm','A5'); $pdf->AddPage('P'); $pdf->SetDisplayMode(real,'default'); $pdf->SetFont('Arial','',10); $txt = file_get_contents('comments.
Adding Image to PDF file by FPDF php'); $pdf = new FPDF(); $pdf->AddPage(); $pdf->Image('images/pdf-header. jpg',0,0); $pdf->Output(); ?> The ouput of above code is here . ( Show Output ) We can add position with height, width and link to above code.
Php require('fpdf. php'); $pdf = new FPDF(); $pdf->AddPage(); $width=$pdf->GetPageWidth(); // Width of Current Page $height=$pdf->GetPageHeight(); // Height of Current Page $pdf->Line(0, 0,$width,$height); // Line one Cross $pdf->Line($width, 0,0,$height); // Line two Cross $pdf->Output(); ?>
I oversaw that there was a function called ->getTemplateSize(). Here's a working snippet:
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($orgpdfpath);
for($i = 1; $i <= $pagecount; $i++){
$tplidx = $pdf->importPage($i);
$specs = $pdf->getTemplateSize($tplidx);
$pdf->addPage($specs['h'] > $specs['w'] ? 'P' : 'L');
$pdf->useTemplate($tplidx);
}
$pdf->addPage($pdforientation);
$pdf->Image($imgpath,$pdfxaxis,$pdfyaxis,$pdfwith,$pdfheight);
$pdf->Output($orgpdfpath,'F');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With