Edit PDF in PHP? [closed]

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.

Leave a Comment