Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit PDF en PHP? [closed]

Tags:

php

pdf

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?

On the front-end

like image 593
kaybenleroll Avatar asked Aug 10 '08 21:08

kaybenleroll


People also ask

Can we edit PDF in PHP?

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.

Can you Edut a PDF?

Click on the “Edit PDF” tool in the right pane. Use Acrobat editing tools: Add new text, edit text, or update fonts using selections from the Format list. Add, replace, move, or resize images on the page using selections from the Objects list.


1 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:

<?php require_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'); 

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.

like image 179
grom Avatar answered Sep 21 '22 23:09

grom