05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Adding an image to a PDF document is relatively simple. The first step is to call the<br />

appropriate open function for the type of image you are using. These functions all<br />

take the form pdf_open_format(). For instance:<br />

$image = pdf_open_jpeg(pdf, filename);<br />

Once you have opened the image, use pdf_place_image( ) to indicate where in your<br />

document the image should be located. While you have an image open, you can<br />

place it multiple times throughout your document; your generated file will contain<br />

only one copy of the actual image data. When you are done placing your image, call<br />

the pdf_close_image( ) function:<br />

pdf_place_image(pdf, image, x, y, scale);<br />

pdf_close_image(pdf, image);<br />

The scale parameter indicates the proportional scaling factor to be used when placing<br />

the image in the document.<br />

You can get the dimensions of an image via pdf_get_value( ) calls on the imagewidth<br />

and imageheight keywords.<br />

Example 10-7 places an image in several places on a page.<br />

Example 10-7. Placing and scaling images<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!