【发布时间】:2012-09-18 06:57:22
【问题描述】:
所以,我使用fpdi,版本 1.2 为我文档的每一页添加一些小标记。这是我的代码:
public static function markPdf($file, $text){
define('FPDF_FONTPATH','font/');
require_once('fpdi/fpdf.php');
require_once('fpdi/fpdi.php');
try{
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($file);
for($i = 1 ; $i <= $pagecount ; $i++){
$tpl = $pdf->importPage($i);
$size = $pdf->getTemplateSize($tpl);
// Here you can see that I'm setting orientation for every single page,
// depending on the orientation of the original page
$orientation = $size['h'] > $size['w'] ? 'P':'L';
$pdf->AddPage($orientation);
$pdf->useTemplate($tpl);
$pdf->SetXY(5, 5);
$pdf->SetTextColor(150);
$pdf->SetFont('Arial','',8);
$pdf->Cell(0,0,$text,0,1,'R');
}
$pdf->Output($file, "F");
}catch(Exception $e){
Logger::log("Exception during marking occurred");
return false;
}
return true;
}
除了一个小问题之外,一切都很好:当我有一个第一页为横向的文档时,生成的文档中的所有页面都从底部和右侧裁剪(如果第一页是纵向模式,一切运行良好,即使后续页面处于横向模式)。 问题很明显:这个函数有什么问题?
【问题讨论】: