Skip to content

{ Category Archives } PDF

Changing Images in a PDF

The PHP routines to fill in PDF forms work great, and now my partner wants to use them too. Changing the forms to make the physician name a fill-in field rather than fixed text is easy, but what to do about the signature? It's not like a check; a pixelated image would be fine (I'm […]

Adding Javascript to PDF Files

I use a lot of forms at work. The more paperless the office gets, the more paper we generate. Every school has its own physical exam form, every government agency has its own application form, every screening test is another form for the parent to fill out. And my handwriting is atrocious. So I try […]

PDF toolkit

Just found another useful tool for manipulating PDF's: the PDF Toolkit. It's a command line tool based on iText that I use mostly for merging PDF's together. The big downside is that embedded Javascript is lost, so that has to be added to the PDF after it has been put together. So my free (as […]

Don’t Reinvent the Wheel, PDF Style

After playing with creating PDFs with PHP using fPDF for a while, and trying to get everything to work consistently, I discovered tcpdf, which is a fork of fpdf that includes everything that anyone has ever added to the original. And I mean everything; this thing is huge! I printed out the source to see […]

Paths, Vector Graphics and PHP images in FPDF

Looking at FPDF and at my PDF tutorial, it is clear that there are a few things that PDF's can do that aren't part of the API of FPDF. However, FPDF is easily extensible to include everything I might find useful, so I put together a package of those routines. See the code. See the […]

Creating PDFs with PHP, part 5: Text

Now we need to add text. That's the most useful part of a PDF, and the easiest. Also the hardest. Sometimes life is like that. See the code.

Creating PDFs with PHP, part 4: Images

Now that we can draw in our PDF, we want to add images. There are two kinds of images, bitmapped and vector. In PDF, images are called XObjects (The X stands for external, meaning defined outside the page). Vector images are easier, since they are just packages of PDF drawing commands, a sort of macro. […]

Creating PDFs with PHP, part 3: Drawing

Now that we can create blank PDF's, it's time to add some stuff. Vector drawing commands (lines and shapes) are simple; you just add the commands to the page content stream. In terms of the original class that would be: $this->pages[count($this->pages)-1]->contents .= "the command\n"; // we just need some whitespace at the end, but the […]

Creating PDFs with PHP, part 2: A Blank Page

Continuing my attempt to dissect FDPF to understand PDF's, we'll create the simplest PDF: a blank page. We need a couple of objects: Catalog This serves as the root object and describes the data structures in the document, which for our purposes is just the collection of printed pages. Other things, like the data for […]

Creating PDFs with PHP: Syntax

I wanted to allow my webservices to create PDF files, and I figured it couldn't be too hard—after all, it's just a bunch of graphics commands in a text file, right? Foolish me. The reference manual is 756 pages long, not including the javascript reference, another 769 pages. The place to start is fPDF, which […]