所以,我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
一切都运行得很好,除了一个小问题:当我有横向第一页的文档时,生成的文档中的所有页面都从底部和右侧裁剪(如果第一页处于纵向模式,一切都很好,即使后续页面处于横向模式).问题很明显:这个功能出了什么问题?
aga*_*aga 12
好的,最后我解决了这个问题.我将调用更改
useTemplate()
为
false
(最重要的是最后一个参数,true默认情况下它的值为fpdf).
我还将所有fpdf相关的库(fpdf_tpl,fpdi和fpdi)更新到最新版本 - 这也很重要.希望它对某人有用.
PS:当useTemplate()推测测试服务器的新版本时,我发现它不适用于相对旧版本的php解释器 - 它适用于5.3.10版本,但它不适用于5.3.2或更早版本.因此,请确保您拥有最新的PHP版本.
| 归档时间: |
|
| 查看次数: |
3789 次 |
| 最近记录: |