php FPDF/FPDI 可以使用横向格式的 PDF 作为模板吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/297899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can FPDF/FPDI use a PDF in landscape format as a template?
提问by Jim OHalloran
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.
我正在尝试使用 FPDI 将现有 PDF 作为模板导入。模板为横向格式。如果我将模板导入到新文档中,模板页面将以纵向形式插入,内容旋转 90 度。如果我的新文档是纵向的,则显示全部内容,但如果新文档也是横向的,则内容会被裁剪。
Is it possible to use a landscape template with FPDI?
是否可以将景观模板与 FPDI 一起使用?
回答by crono
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)
当然,这没问题。调用“addPage()”时只需添加“L”作为参数。这是一个对我来说很好用的示例(模板是横向的)
<?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');
?>
回答by Jim OHalloran
Finally got to look at this problem again... Although crono's answer is perfectly valid. It seems this only works with more recent versions of the FPDI tools. Upgrading from v1.1 to v1.3 solves the problem.
终于再次看到这个问题......虽然crono的答案是完全有效的。似乎这只适用于更新版本的 FPDI 工具。从 v1.1 升级到 v1.3 解决了这个问题。

