Edit Existing Pdf Using Php

  

Active2 years, 11 months ago

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?

MarkoMarko
2,9661 gold badge20 silver badges22 bronze badges

1 Answer

You want to use FPDI.

There's some example code here.

timdevtimdev
51.3k6 gold badges69 silver badges90 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged phppdftcpdf or ask your own question.

Active1 year, 2 months ago

Does anyone know of a good method for editing PDFs in PHP? Preferably open-source/zero-license cost methods. :)

Edit

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.

kaybenlerollkaybenleroll
7,98816 gold badges47 silver badges66 bronze badges

closed as too broad by animusonSep 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.

gromgrom
11.6k13 gold badges58 silver badges64 bronze badges

There 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.

metatronmetatron

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énager
140k3 gold badges35 silver badges58 bronze badges
AdamTheHuttAdamTheHutt
3,3347 gold badges28 silver badges30 bronze badges

Zend Framework can load and edit existing PDF files. I think it supports revisions too.

Php

I use it to create docs in a project, and it works great. Never edited one though.

Check out the doc here

JuanJuan

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 Hein
71.7k84 gold badges196 silver badges251 bronze badges

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.

RossRoss
30.2k35 gold badges109 silver badges166 bronze badges

Tcpdf is also a good liabrary for generating pdf in php http://www.tcpdf.org/

MufaddalMufaddal
5,1987 gold badges38 silver badges56 bronze badges

I 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.

Edit existing pdf using phpmyadmin
josh.chavannejosh.chavanne

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
87.9k52 gold badges199 silver badges278 bronze badges
kaybenleroll
7,98816 gold badges47 silver badges66 bronze badges
NitinNitin

How To Edit Existing Pdf File

Not the answer you're looking for? Browse other questions tagged phppdf or ask your own question.