Edit Existing Pdf Using Php Agency
Sep 02, 2015 Can anyone suggest me how to Edit Existing multiple pdf using fpdf Library in PHP I have explored many php developer forum related to this issue but I am unable to get satisfactory solutions. Hope this forum help me out for the same issue. Hi, How do I use php to edit a pdf file? Specifically, I would like to upload a pdf file, find a specified string of text (e.g. Google) and replace it with another string (e.g. Modifying PDF files with PHP. None seem to have capabilities to modify the contents of an existing PDF file. Their manuals/tutorials are full of.
I have several PDF templates that I would like to load and modify and output using tcpdf.
Is it possible to load an existing PDF and use it as a starting point in tcpdf?
MarkoMarko1 Answer
You want to use FPDI.
There's some example code here.
timdevtimdevNot the answer you're looking for? Browse other questions tagged phppdftcpdf or ask your own question.
Does anyone know of a good method for editing PDFs in PHP? Preferably open-source/zero-license cost methods. :)
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?
I have programmatically created PDF files in the past using FPDF, but found it a little unwieldy at times.
kaybenlerollkaybenlerollclosed as too broad by animuson♦Sep 8 '14 at 17:16
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
10 Answers
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:
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.
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.
gromgromThere is a free and easy to use PDF class to create PDF documents. It's called FPDF. In combination with FPDI (http://www.setasign.de/products/pdf-php-solutions/fpdi) it is even possible to edit PDF documents. The following code shows how to use FPDF and FPDI to fill an existing gift coupon with the user data.
If you need really simple PDFs, then Zend or FPDF 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.
For that reason, I use dompdf, 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.
Fabien MénagerZend Framework can load and edit existing PDF files. I think it supports revisions too.
I use it to create docs in a project, and it works great. Never edited one though.
Check out the doc here
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.
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.
But again, this uses FPDF, so if you don't want to use that, then it won't work.
Darryl HeinDarryl HeinThe PDF/pdflib extension documentation in PHP is sparse (something that has been noted in bugs.php.net) - I reccommend you use the Zend library.
RossRossTcpdf is also a good liabrary for generating pdf in php http://www.tcpdf.org/
MufaddalMufaddalI really had high hopes for dompdf (it is a cool idea) but the positioning issue are a major factor in my using fpdf. Though it is tedious as every element has to be set; it is powerful as all get out.
I lay an image underneath my workspace in the document to put my layout on top of to fit. Its always been sufficient even for columns (requires a tiny bit of php string calculation, but nothing too terribly heady).
Good luck.
We use pdflib to create PDF files from our rails apps. It has bindings for PHP, and a ton of other languages.
We use the commmercial version, but they also have a free/open source version which has some limitations.
Unfortunately, this only allows creation of PDF's.
If you want to open and 'edit' existing files, pdflib do provide a product which does this this, but costs a LOT
Orion EdwardsOrion Edwards