Search code examples
phpzend-frameworkpdfjoomla

Insert Text in PDF with PHP but without Zend Framework


At the moment I am using this code to insert text in a PDF:

$pdf = Zend_Pdf::load("test_document.pdf");
$font = Zend_Pdf_Font::fontWithPath('arial_unicode_ms.ttf');
foreach ($pdf->pages as &$page) {
   $page->setFont($font, 12);
   $page->drawText("Inserted some text.", 200, 10);
}

The problem is, that I want to include this functionality in a Joomla plugin and I don't want to include all the data from Zend Framework to my project.

Is there any easy way or any small library which provides this pdf tagging mechanism?


Solution

  • If you still want to use Zend_Pdf, you'll probably need to have a look at the dependencies in the Zend/Pdf directory. You can grep for require_once to have a rough idea, and filter out the Zend/Pdf results:

    grep -r require_once Pdf.php Pdf | grep -v "Zend/Pdf"
    

    The first step outputs Zend_Memory, Zend_Exception and Zend_Log.

    You can follow a similar method to check additional dependencies, and you'll see that Zend_Memory needs Zend_Cache, which needs only Zend_Log, which is self-contained, like Zend_Exception. I think you won't need to go much further, once you have included these four additional libraries.

    EDIT: I found this link that lists all the dependencies between ZF modules (don't know how up to date it is, though): http://files.zend.com/help/Zend-Framework/requirements.dependencies.html

    Hope that helps,