我是FPDI来编辑我现有的pdf文件,它的工作非常适合单页.你可以看到我正在编辑我的$tplIdx = $pdf->importPage(1);第一页.我有六页的pdf文件,需要在不同的页面中添加2个变量.
有可能吗?怎么样?
<?php
require_once('fpdf.php');
require_once('fpdi.php');
// initiate FPDI
$pdf = new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('ex.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
$pdf->useTemplate($tplIdx, 10, 10, 200);
// now write some text above the imported page
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(50, 50);
$pdf->Write(0, "Ajay Patel");
$pdf->Output('newpdf1.pdf', 'D');
?>
Run Code Online (Sandbox Code Playgroud)
提前致谢 !
J A*_*J A 11
没有安装FPDI就很难尝试.但我认为核心理念将遵循:
<?php
require_once('fpdf.php');
require_once('fpdi.php');
// initiate FPDI
$pdf = new FPDI();
/* <Virtual loop> */
$pdf->AddPage();
$pdf->setSourceFile('ex.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 200);
// now write some text above the imported page
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(50, 50);
$pdf->Write(0, "Ajay Patel");
/* </Virtual loop/> */
$pdf->AddPage();
//$pdf->setSourceFile('ex.pdf');
$tplIdx = $pdf->importPage(2);
$pdf->useTemplate($tplIdx, 10, 10, 200); // dynamic parameter based on your page
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(50, 50);
$pdf->Write(0, "Ajay Patel2");
$pdf->Output('newpdf1.pdf', 'D');
?>
Run Code Online (Sandbox Code Playgroud)
如果这样可行,您可以摆脱代码的第二个块并在循环中进行此操作(以及动态定位).