4
因此,我使用fpdi
版本1.2为我的文档中的每个页面添加一些小标记。这里是我的代码:为什么fpdi会裁剪pdf页面?
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;
}
,一切工作得很好,除了一个小问题:当我有在横向第一页的文档,生成的文档中的所有页面都从底部和右侧裁剪(如果第一页是纵向模式,即使后续页面处于横向模式,一切都很顺利)。 问题很明显:这个函数有什么问题?
谢谢你。这帮助了我很多,你不知道。 – bryan
@bryan不用客气。 :) – aga
当我使用这段代码时,它在PDF的右侧和底部添加了非常大的空白,你能帮助我吗?我在一个文档中有不同大小页面的PDF – RPDeshaies