网站如何做好seo,地方行业网站,厦门网站建设哪家公司好,视频网站怎么做采集用PHP编辑PDF#xff1f;有谁知道在PHP中编辑PDF的好方法#xff1f; 优选地是开源/零许可证成本方法。:)我正在考虑打开PDF文件#xff0c;替换PDF中的文本然后写出PDF的修改版本#xff1f;我过去使用FPDF以编程方式创建了PDF文件#xff0c;但有时发现它有点笨拙。kayb…用PHP编辑PDF有谁知道在PHP中编辑PDF的好方法 优选地是开源/零许可证成本方法。:)我正在考虑打开PDF文件替换PDF中的文本然后写出PDF的修改版本我过去使用FPDF以编程方式创建了PDF文件但有时发现它有点笨拙。kaybenleroll asked 2019-06-14T17:09:38Z10个解决方案64 votes如果您采用“填空”方法则可以在页面上的任何位置精确定位文本。 因此将缺少的文本添加到文档中相对容易(如果不是有点乏味)。 例如使用Zend Frameworkrequire_once Zend/Pdf.php;$pdf Zend_Pdf::load(blank.pdf);$page $pdf-pages[0];$font Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);$page-setFont($font, 12);$page-drawText(Hello world!, 72, 720);$pdf-save(zend.pdf);如果您尝试替换内联内容例如“[占位符字符串]”则会变得更加复杂。 虽然技术上可行但您可能会弄乱页面布局。PDF文档由一组原始绘图操作组成此处为line此处为image其中为text chunk等。它不包含有关这些基元的布局意图的任何信息。grom answered 2019-06-14T17:10:08Z38 votes有一个免费且易于使用的PDF类来创建PDF文档。 它被称为FPDF。 结合FPDI([http://www.setasign.de/products/pdf-php-solutions/fpdi)]甚至可以编辑PDF文档。以下代码显示如何使用FPDF和FPDI使用用户数据填充现有礼品券。require_once(fpdf.php);require_once(fpdi.php);$pdf new FPDI();$pdf-AddPage();$pdf-setSourceFile(gift_coupon.pdf);// import page 1$tplIdx $this-pdf-importPage(1);//use the imported page and place it at point 0,0; calculate width and height//automaticallay and ajust the page size to the size of the imported page$this-pdf-useTemplate($tplIdx, 0, 0, 0, 0, true);// now write some text above the imported page$this-pdf-SetFont(Arial, , 13);$this-pdf-SetTextColor(0,0,0);//set position in pdf document$this-pdf-SetXY(20, 20);//first parameter defines the line height$this-pdf-Write(0, gift code);//force the browser to download the output$this-pdf-Output(gift_coupon_generated.pdf, D);metatron answered 2019-06-14T17:10:32Z18 votes如果您需要非常简单的PDF那么Zend或FPDF就可以了。 然而我发现它们很难和令人沮丧。 此外由于API的工作方式没有好的方法将内容与表示与业务逻辑分开。出于这个原因我使用dompdf它自动将HTML和CSS转换为PDF文档。 您可以像对HTML页面一样布局模板并使用标准HTML语法。 您甚至可以包含外部CSS文件。 库不完美非常复杂的标记或css有时会被破坏但我还没有发现其他任何有用的东西。AdamTheHutt answered 2019-06-14T17:11:08Z3 votesZend Framework可以加载和编辑现有的PDF文件。 我认为它也支持修订。我用它来创建一个项目中的文档它工作得很好。 从来没有编辑过。在这里查看文档Juan answered 2019-06-14T17:11:48Z3 votes不知道这是否是一个选项但它与Zend的pdf库非常相似但你不需要加载一堆额外的代码(zend框架)。 它只是扩展了FPDF。[http://www.setasign.de/products/pdf-php-solutions/fpdi/]在这里你基本上可以做同样的事情。 加载PDF在其上面书写然后保存到新的PDF。 在FPDI中您基本上将PDF作为图像插入以便您可以将任何内容放在上面。但同样这使用FPDF所以如果你不想使用它那么它将无法工作。Darryl Hein answered 2019-06-14T17:12:36Z2 votesPHP中的PDF / pdflib扩展文档很稀疏(在bugs.php.net中已经注意到了这一点) - 我建议你使用Zend库。Ross answered 2019-06-14T17:13:00Z2 votesTcpdf也是在php中生成pdf的好方法 [http://www.tcpdf.org/]Mufaddal answered 2019-06-14T17:13:26Z1 votes我真的对dompdf寄予厚望(这是一个很酷的主意)但定位问题是我使用fpdf的一个主要因素。 虽然每个元素都必须设置但这很乏味; 所有人都出来了它是强大的。我在文档的工作区下面放置一个图像将我的布局放在最适合的位置。 即使对于列它总是足够的(需要一点点的PHP字符串计算但没有什么太可怕的令人生气)。祝好运。josh.chavanne answered 2019-06-14T17:14:01Z0 votes我们使用pdflib从我们的rails应用程序创建PDF文件。 它有PHP和大量其他语言的绑定。我们使用商业版但他们也有免费/开源版本但有一些限制。不幸的是这只允许创建PDF。如果你想打开并“编辑”现有文件pdflib会提供一个这样做的产品但成本很高Orion Edwards answered 2019-06-14T17:14:47Z0 votes//getting new instance$pdfFile new_pdf();PDF_open_file($pdfFile, );//document infopdf_set_info($pdfFile, Auther, Ahmed Elbshry);pdf_set_info($pdfFile, Creator, Ahmed Elbshry);pdf_set_info($pdfFile, Title, PDFlib);pdf_set_info($pdfFile, Subject, Using PDFlib);//starting our page and define the width and highet of the documentpdf_begin_page($pdfFile, 595, 842);//check if Arial font is found, or exitif($font PDF_findfont($pdfFile, Arial, winansi, 1)) {PDF_setfont($pdfFile, $font, 12);} else {echo (Font Not Found!);PDF_end_page($pdfFile);PDF_close($pdfFile);PDF_delete($pdfFile);exit();}//start writing from the point 50,780PDF_show_xy($pdfFile, This Text In Arial Font, 50, 780);PDF_end_page($pdfFile);PDF_close($pdfFile);//store the pdf document in $pdf$pdf PDF_get_buffer($pdfFile);//get the len to tell the browser about it$pdflen strlen($pdfFile);//telling the browser about the pdf documentheader(Content-type: application/pdf);header(Content-length: $pdflen);header(Content-Disposition: inline; filenamephpMade.pdf);//output the documentprint($pdf);//delete the objectPDF_delete($pdfFile);?Nitin answered 2019-06-14T17:15:05Z