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.

You specify the paper size in points in the call to pdf_begin_page( ). Table 10-1<br />

shows some typical sizes.<br />

Table 10-1. Paper sizes<br />

Page format Width Height<br />

US-Letter 612 792<br />

US-Legal 612 1008<br />

US-Ledger 1224 792<br />

11 × 17 792 1224<br />

A0 2380 3368<br />

A1 1684 2380<br />

A2 1190 1684<br />

A3 842 1190<br />

A4 595 842<br />

A5 421 595<br />

A6 297 421<br />

B5 501 709<br />

Here is some typical begin/end page code:<br />

<br />

Outputting Basic Text<br />

To put text on a page, you must select the font you want to use, set the default font<br />

to be that font at a particular size, and then add the text. For example:<br />

$font = pdf_findfont($pdf, "Times-Roman", "host", 0);<br />

pdf_setfont($pdf, $font, 48);<br />

pdf_show_xy($pdf, "Hello, World", 200, 200);<br />

With PDF documents, the (0,0) coordinate indicates the bottom-left corner of the<br />

page. In later sections we’ll examine the different aspects of fonts and text layout and<br />

explain these functions in detail.<br />

Terminating and Streaming a PDF Document<br />

Call pdf_close( ) to complete the PDF document. If no filename was provided in the<br />

pdf_open_file( ) call, you can now use the pdf_get_buffer( ) function to fetch the<br />

PDF buffer from memory. To send the file to the browser, you must send Content-<br />

236 | Chapter 10: PDF<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!