Reputation: 71
The PDF file have a large width than normal.
$pagecount = $mpdf->SetSourceFile($pdfurl);
for($x=0;$x<$pagecount;$x++){
$tplId = $mpdf->ImportPage(($x+1));
$mpdf->UseTemplate($tplId);
$mpdf->AddPage();
}
Most PDF is displayed well, but with large width, it only display a part of it.
Upvotes: 0
Views: 1238
Reputation: 71
Thanks @Jan.Your code not work perfectly for me.But point me the right direction.
for($pageNo = 1; $pageNo <= $pageCount ; $pageNo++){
$tplId = $mpdf->ImportPage($pageNo);
$size = $mpdf->GetTemplateSize($tplId);
$w=210;
if($size['w'] > $size['h']){
$w=299;
}
$mpdf->AddPageByArray([
'orientation' => $size['w'] > $size['h'] ? 'L' : 'P'
]);
$mpdf->UseTemplate($tplId,0,0,$w);
}
But my solution got a problem.The landscape mode will scale the PDF size a little small.
Upvotes: 0
Reputation: 5058
There are several issues in your code:
So you have to change your script to:
$pageCount = $mpdf->SetSourceFile($pdfurl);
for($pageNo = 1; $pageNo <= $pageCount ; $pageNo++){
$tplId = $mpdf->ImportPage($pageNo);
$size = $mpdf->GetTemplateSize($pageNo);
$mpdf->AddPageByArray([
'orientation' => $size['w'] > $size['h'] ? 'L' : 'P',
'newformat' => [$size['w'], $size['h']]
]);
$mpdf->UseTemplate($tplId);
}
Upvotes: 1