05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A Simple Example<br />

Let’s start with a simple PDF document. Example 10-1 simply places “Hello world!”<br />

on a page and then displays the resulting PDF document.<br />

Example 10-1. Hello world in PDF<br />

<br />

Example 10-1 follows the basic steps involved in creating a PDF document: creating<br />

a new document, setting some metadata for the document, creating a page, and writing<br />

text to the page. Figure 10-1 shows the output of Example 10-1.<br />

Initializing the Document<br />

In Example 10-1, we started by calling pdf_new( ), to create a new PDF data structure,<br />

followed by pdf_open_file( ), to open a new document. pdf_open_file( ) takes<br />

an optional second argument that, when set, specifies the filename to which to write<br />

the PDF data:<br />

pdf_open_file(pdf [, filename ]);<br />

The output of pdf_open_file( ) is sent to stdout if the filename is "-". Ifnofilename<br />

argument is provided, the PDF data is written to a memory buffer, which can later be<br />

fetched by calling pdf_get_buffer( ). The latter approach is the one we used in<br />

Example 10-1.<br />

234 | 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!