K B
K B

Reputation: 1340

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?

Upvotes: 1

Views: 747

Answers (3)

vascowhite
vascowhite

Reputation: 18430

There are other pdf libraries available. I have used tcpdf in place of Zend_Pdf occassionally. It is all self contained, so you won't have any dependency issues with it.

In answer to your comment

I started using TCPDF as Zend_Pdf was incomplete and I needed a solution that would allow me to use existing pdf's as base documents as you seem to need. The solution I eventually opted for was to use FPDI in conjunction with TCPDF.

I haven't worked on that project for a while now, but I used the FPDI web site as the start of the solution that eventually worked for me.

I'm not sure if it will be a solution for you too, but it's worth having a look.

Upvotes: 2

dinopmi
dinopmi

Reputation: 2673

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,

Upvotes: 3

Pete Mitchell
Pete Mitchell

Reputation: 2879

It is not necessary to include the whole Zend Framework with your project, you only need to include the Zend/Pdf.php and the Zend/Pdf folder. This isn't that large (combined size of ~ 1.2mb).

Upvotes: 1

Related Questions