Drawing A Image In A PDF With Zend Framework

I recently wrote about Creating A Simple PDF With The Zend Framework, and so I thought I’d take a quick look at Zend_PDF’s Drawing Methods.

As you may know I work for a company called Bauer and we have a very simple logo. It’s basically a blue square, with a gray triangle in the top right hand corner and the name BAUER in white at the bottom. This sounds like an ideal image to try to recreate using Zend_PDF.

Bauer Media Logo

Take a look at my previous article on PDF’s and Zend Framework for an explanation of setting up a document and page to draw on. I will assume this page has been setup and is available in the $page variable.

Firstly we need to prepare a font for use. I don’t know the font Bauer use, so I’ll just use Helvetica Bold in this example.

The background is a blue square, so I need to set the fill colour to the shade of blue Bauer use, then draw the square using this colour.

As you can see, I’ve decided to make the logo 200×200 in size.

Now it’s time to write BAUER at the bottom in white using the font we prepared earlier.

Firstly I set the fill colour to white. Next I select the font and set it’s size. Finally I write the word BAUER at co-ordinates 7,10, which happens to be at the bottom of the blue square.

Finally it’s time to draw the gray triangle in the top right corner of the blue square.

As before, I set the fill colour, this time to gray. Now I use the drawPolygon method to draw the triangle. As you can see there are two arrays there, the first are the x co-ordinates of the triangle, the second are the y co-ordinates of the triangle. The fill method is the last parameter, it’s the same as the one we used when drawing the blue square.

We should now have our Bauer logo on the page!

generated copy of the Bauer Media logo

I don’t think that Bauer will be sacking their design team in a hurry, but it’s quite a close approximation of the logo.

Here’s a copy of the finished code.

Leave a Reply