Php 如何使用FPDF/FPDI获得精确修改的PDF?
我的任务是修改PDF并向其中添加图像,为此我使用了FPDF和FPDI库。。其操作代码如下所示:Php 如何使用FPDF/FPDI获得精确修改的PDF?,php,pdf,fpdf,fpdi,Php,Pdf,Fpdf,Fpdi,我的任务是修改PDF并向其中添加图像,为此我使用了FPDF和FPDI库。。其操作代码如下所示: <?php require_once('fpdf.php'); require_once('fpdi.php'); $pdf =& new FPDI(); $pdf->AddPage(); //Set the source PDF file $pagecount = $pdf->setSourceFile("Completed.pdf"); //Import the f
<?php
require_once('fpdf.php');
require_once('fpdi.php');
$pdf =& new FPDI();
$pdf->AddPage();
//Set the source PDF file
$pagecount = $pdf->setSourceFile("Completed.pdf");
//Import the first page of the file
$tpl = $pdf->importPage(1);
//Use this page as template
// use the imported page and place it at point 20,30 with a width of 170 mm
$pdf->useTemplate($tpl, 20, 30, 170);
#Print Hello World at the bottom of the page
//Select Arial italic 8
$pdf->SetFont('Arial','',8);
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(90, 160);
//$pdf->Rotate(90);
$pdf->Image('think.jpg',120,240,20,20);
$pdf->Image('think.jpg',120,260,20,20);
//$pdf->Write(0, "Hello World");
$pdf->Output("modified_pdf.pdf", "F");
?>
但是当我得到修改后的pdf时,我可以得到非常扭曲的修改后的pdf。。。其屏幕截图如下所示:
<?php
require_once('fpdf.php');
require_once('fpdi.php');
$pdf =& new FPDI();
$pdf->AddPage();
//Set the source PDF file
$pagecount = $pdf->setSourceFile("Completed.pdf");
//Import the first page of the file
$tpl = $pdf->importPage(1);
//Use this page as template
// use the imported page and place it at point 20,30 with a width of 170 mm
$pdf->useTemplate($tpl, 20, 30, 170);
#Print Hello World at the bottom of the page
//Select Arial italic 8
$pdf->SetFont('Arial','',8);
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(90, 160);
//$pdf->Rotate(90);
$pdf->Image('think.jpg',120,240,20,20);
$pdf->Image('think.jpg',120,260,20,20);
//$pdf->Write(0, "Hello World");
$pdf->Output("modified_pdf.pdf", "F");
?>
原始文件如下所示:
<?php
require_once('fpdf.php');
require_once('fpdi.php');
$pdf =& new FPDI();
$pdf->AddPage();
//Set the source PDF file
$pagecount = $pdf->setSourceFile("Completed.pdf");
//Import the first page of the file
$tpl = $pdf->importPage(1);
//Use this page as template
// use the imported page and place it at point 20,30 with a width of 170 mm
$pdf->useTemplate($tpl, 20, 30, 170);
#Print Hello World at the bottom of the page
//Select Arial italic 8
$pdf->SetFont('Arial','',8);
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(90, 160);
//$pdf->Rotate(90);
$pdf->Image('think.jpg',120,240,20,20);
$pdf->Image('think.jpg',120,260,20,20);
//$pdf->Write(0, "Hello World");
$pdf->Output("modified_pdf.pdf", "F");
?>
因此,有谁能帮助我使用相同的代码/修改过的代码检索正确的修改过的PDF吗?使用TCPDF它很好…它的fpdf_tpl.php文件需要用新的下载更新@Gordan你能帮我吗?@Pekka你能帮我吗?最近面临同样的问题,当保存到文件时,fpdf中似乎存在一个错误-加载相同生成的pdf工作。我最终导出到xls而不是pdf。看起来字体已损坏,您是否尝试比较二进制文件?@Maerlyn@p4553d感谢您的关注,因为它是一个BUG。。但不幸的是,我需要得到的PDF文件,而不是…它会修改我现有的PDF文件,并写在所需的位置图像?