Showing posts with label PDF. Show all posts
Showing posts with label PDF. Show all posts

Monday, October 18, 2010

Add Text to an Existing PDF Using PHP

I am finishing up on a project right now that fills out a PDF application for a merchant account. The software helps the user through the application process by asking more targeted questions and filling in fields that are known. In order to do this I had found two PHP libraries that work quite well.

The first is FPDF. It is a free PHP library that allows you to create PDFs. It is not a module or binary code, just a straight up PHP script library. Color me impressed. You can download it at http://www.fpdf.org/

The second bit of code you need is called FPDI. This will import a PDF as a template and allow you to overlay text. It worked quite well for my project as I was taking an existing PDF and filling in fields on top of it. Just like FPDF, it is super easy to install because all it is is a collection of PHP script files. You can download it at http://www.setasign.de/products/pdf-php-solutions/fpdi/

Here is a quick demo by FPDI on how to use these two modules together.

To make it all work I created a flat, PDF version of the template PDF. I removed all of the form fields using Adobe Acrobat. The first run I got an error: "probably uses a compression technique which is not supported". This was easily fixed by saving the PDF as PDF/A using Adobe Acrobat. (Update below.)

If you have any questions, please let me know. I'd be glad to share more of what I learned.

Update (10/22/10): I've learned that saving the PDf as a PDF/A doesn't always solve the error I explained above. What has worked, however, is running Adobe Pre-Flight on the document. If you go to "Advanced" > "Print Production" > "Preflight" and then click on "Analyze and fix", Adobe will work some magic on the document and make it work with FPDI.

Update (1/27/11): FPDI, the free version of the PDF parser, requires the PDF to be version 1.4 or below. To save a PDF in this format, open the document in Adobe Acrobat, click "Save As" and then select the type "PDF, Optimized" then click the "Settings" button and select "Adobe Acrobat 5.0". This will save the PDF in version 1.4, which was last used in Adobe Acrobat 5.0!

Thursday, November 20, 2008

PDF Creator

Whenever posting documents to the internet (or emailing them) it is always best to use PDFs. Using a PDF ensures that the document will look exactly like you intended it. If you use Word or Excel or something similar, there is always the chance that someone else wont have the same version or same fonts and that the end result will look very different. And, not everyone has the same software programs--Microsoft Office is expensive. But, Adobe Acrobat Reader is free! Also, it is generally more professional to send documents in PDF, such as invoices or proposals.

So, how do you create these PDFs without dishing out all the cash for Adobe Acrobat, the not-so-free version? I have been using the free PDF creator PrimoPDF for some time now. I really like it and it has not given me any problems. It creates great looking PDFs very quickly. It installs a new printer on your computer so that you can create a PDF from any program. But instead of something being printed physically it creates a PDF file that you can save.

Works great and it is free. Two things I value, as is apparent by previous blog posts. :)