<p>Does anyone know of a good method for editing PDFs in PHP? Preferably open-source/zero-license cost methods. :)</p>
<p>I am thinking along the lines of opening a PDF file, replacing text in the PDF and then writing out the modified version of the PDF?</p>
<p>On the front-end</p>

[{'answer_id': 7377, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': -1, 'selected': False, 'text': '<p>We use <a href="http://www.pdflib.com/pdflib-gmbh/" rel="nofollow noreferrer">pdflib</a> to create PDF files from our rails apps. It has bindings for PHP, and a ton of other languages.</p>\n<p>We use the commmercial version, but they also have a <a href="http://www.pdflib.com/download/pdflib-family/pdflib-lite/" rel="nofollow noreferrer">free/open source version</a> which has some limitations.</p>\n<p>Unfortunately, this only allows creation of PDF\'s.</p>\n<p>If you want to open and \'edit\' existing files, pdflib do provide <a href="http://www.pdflib.com/products/pdflib-family/pdi/" rel="nofollow noreferrer">a product which does this this</a>, but costs a <a href="https://www.pdflib.com/buy/online-shop/pdflib-pdflib-pdi-pps/" rel="nofollow noreferrer">LOT</a></p>\n'}, {'answer_id': 7402, 'author': 'Juan', 'author_id': 550, 'author_profile': 'https://Stackoverflow.com/users/550', 'pm_score': 2, 'selected': False, 'text': '<p>Zend Framework can load and edit existing PDF files. I think it supports revisions too.</p>\n<p>I use it to create docs in a project, and it works great. Never edited one though.</p>\n<p>Check out the doc <a href="https://web.archive.org/web/20120822101532/http://framework.zend.com:80/manual/en/zend.pdf.create.html" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 7455, 'author': 'grom', 'author_id': 486, 'author_profile': 'https://Stackoverflow.com/users/486', 'pm_score': 7, 'selected': True, 'text': '<p>If you are taking a \'fill in the blank\' approach, you can precisely position text anywhere you want on the page. So it\'s relatively easy (if not a bit tedious) to add the missing text to the document. For example with Zend Framework:</p>\n\n<pre><code>&lt;?php\nrequire_once \'Zend/Pdf.php\';\n\n$pdf = Zend_Pdf::load(\'blank.pdf\');\n$page = $pdf-&gt;pages[0];\n$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);\n$page-&gt;setFont($font, 12);\n$page-&gt;drawText(\'Hello world!\', 72, 720);\n$pdf-&gt;save(\'zend.pdf\');\n</code></pre>\n\n<p>If you\'re trying to replace inline content, such as a "[placeholder string]," it gets much more complicated. While it\'s technically possible to do, you\'re likely to mess up the layout of the page.</p>\n\n<p>A PDF document is comprised of a set of primitive drawing operations: line here, image here, text chunk there, etc. It does not contain any information about the layout intent of those primitives.</p>\n'}, {'answer_id': 20407, 'author': 'Ross', 'author_id': 2025, 'author_profile': 'https://Stackoverflow.com/users/2025', 'pm_score': 2, 'selected': False, 'text': '<p>The PDF/pdflib extension documentation in PHP is sparse (something that has been noted in bugs.php.net) - I reccommend you use the Zend library.</p>\n'}, {'answer_id': 29835, 'author': 'AdamTheHutt', 'author_id': 1103, 'author_profile': 'https://Stackoverflow.com/users/1103', 'pm_score': 4, 'selected': False, 'text': '<p>If you need really simple PDFs, then Zend or <a href="http://www.fpdf.org/" rel="noreferrer">FPDF</a> is fine. However I find them difficult and frustrating to work with. Also, because of the way the API works, there\'s no good way to separate content from presentation from business logic.</p>\n\n<p>For that reason, I use <a href="https://github.com/dompdf/dompdf" rel="noreferrer">dompdf</a>, which automatically converts HTML and CSS to PDF documents. You can lay out a template just as you would for an HTML page and use standard HTML syntax. You can even include an external CSS file. The library isn\'t perfect and very complex markup or css sometimes gets mangled, but I haven\'t found anything else that works as well.</p>\n'}, {'answer_id': 53075, 'author': 'Darryl Hein', 'author_id': 5441, 'author_profile': 'https://Stackoverflow.com/users/5441', 'pm_score': 2, 'selected': False, 'text': '<p>Don\'t know if this is an option, but it would work very similar to Zend\'s pdf library, but you don\'t need to load a bunch of extra code (the zend framework). It just extends FPDF.</p>\n\n<p><a href="http://www.setasign.de/products/pdf-php-solutions/fpdi/" rel="nofollow noreferrer">http://www.setasign.de/products/pdf-php-solutions/fpdi/</a></p>\n\n<p>Here you can basically do the same thing. Load the PDF, write over top of it, and then save to a new PDF. In FPDI you basically insert the PDF as an image so you can put whatever you want over it.</p>\n\n<p>But again, this uses FPDF, so if you don\'t want to use that, then it won\'t work.</p>\n'}, {'answer_id': 1598933, 'author': 'Nitin', 'author_id': 193592, 'author_profile': 'https://Stackoverflow.com/users/193592', 'pm_score': -1, 'selected': False, 'text': '<pre><code>&lt;?php\n\n//getting new instance\n$pdfFile = new_pdf();\n\nPDF_open_file($pdfFile, " ");\n\n//document info\npdf_set_info($pdfFile, "Auther", "Ahmed Elbshry");\npdf_set_info($pdfFile, "Creator", "Ahmed Elbshry");\npdf_set_info($pdfFile, "Title", "PDFlib");\npdf_set_info($pdfFile, "Subject", "Using PDFlib");\n\n//starting our page and define the width and highet of the document\npdf_begin_page($pdfFile, 595, 842);\n\n//check if Arial font is found, or exit\nif($font = PDF_findfont($pdfFile, "Arial", "winansi", 1)) {\n    PDF_setfont($pdfFile, $font, 12);\n} else {\n    echo ("Font Not Found!");\n    PDF_end_page($pdfFile);\n    PDF_close($pdfFile);\n    PDF_delete($pdfFile);\n    exit();\n}\n\n//start writing from the point 50,780\nPDF_show_xy($pdfFile, "This Text In Arial Font", 50, 780);\nPDF_end_page($pdfFile);\nPDF_close($pdfFile);\n\n//store the pdf document in $pdf\n$pdf = PDF_get_buffer($pdfFile);\n//get  the len to tell the browser about it\n$pdflen = strlen($pdfFile);\n\n//telling the browser about the pdf document\nheader("Content-type: application/pdf");\nheader("Content-length: $pdflen");\nheader("Content-Disposition: inline; filename=phpMade.pdf");\n//output the document\nprint($pdf);\n//delete the object\nPDF_delete($pdfFile);\n?&gt;\n</code></pre>\n'}, {'answer_id': 4184326, 'author': 'metatron', 'author_id': 508238, 'author_profile': 'https://Stackoverflow.com/users/508238', 'pm_score': 6, 'selected': False, 'text': '<p>There is a free and easy to use PDF class to create PDF documents. It\'s called <a href="http://www.fpdf.org/" rel="noreferrer">FPDF</a>. In combination with FPDI (<a href="http://www.setasign.de/products/pdf-php-solutions/fpdi" rel="noreferrer">http://www.setasign.de/products/pdf-php-solutions/fpdi</a>) it is even possible to edit PDF documents. \nThe following code shows how to use FPDF and FPDI to fill an existing gift coupon with the user data.</p>\n\n<pre><code>require_once(\'fpdf.php\'); \nrequire_once(\'fpdi.php\'); \n$pdf = new FPDI();\n\n$pdf-&gt;AddPage(); \n\n$pdf-&gt;setSourceFile(\'gift_coupon.pdf\'); \n// import page 1 \n$tplIdx = $this-&gt;pdf-&gt;importPage(1); \n//use the imported page and place it at point 0,0; calculate width and height\n//automaticallay and ajust the page size to the size of the imported page \n$this-&gt;pdf-&gt;useTemplate($tplIdx, 0, 0, 0, 0, true); \n\n// now write some text above the imported page \n$this-&gt;pdf-&gt;SetFont(\'Arial\', \'\', \'13\'); \n$this-&gt;pdf-&gt;SetTextColor(0,0,0);\n//set position in pdf document\n$this-&gt;pdf-&gt;SetXY(20, 20);\n//first parameter defines the line height\n$this-&gt;pdf-&gt;Write(0, \'gift code\');\n//force the browser to download the output\n$this-&gt;pdf-&gt;Output(\'gift_coupon_generated.pdf\', \'D\');\n</code></pre>\n'}, {'answer_id': 10799330, 'author': 'Mufaddal', 'author_id': 1326539, 'author_profile': 'https://Stackoverflow.com/users/1326539', 'pm_score': 0, 'selected': False, 'text': '<p>Tcpdf is also a good liabrary for generating pdf in php\n<a href="http://www.tcpdf.org/" rel="nofollow"> http://www.tcpdf.org/</a></p>\n'}]
['https://Stackoverflow.com/questions/7364', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/277/']