13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

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

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

Solution Overview<br />

795<br />

Font sizes are specified in points. In this case, we chose host character encoding.The<br />

allowable values are winansi, builtin, macroman, ebcdic, or host. The meanings of the<br />

different values are as follows:<br />

n winansi—Uses ISO 8859-1 plus special characters added by Microsoft, such as a<br />

Euro symbol.<br />

n builtin—Uses the encoding built into the font. Normally used with non-Latin<br />

fonts <strong>and</strong> symbols.<br />

n macroman—Uses Mac Roman encoding.The default Macintosh character set.<br />

n ebcdic—Uses EBCDIC as used on IBM AS/400 systems.<br />

n host—Automatically selects macroman on a Macintosh, ebcdic on an EBCDICbased<br />

system, <strong>and</strong> winansi on all other systems.<br />

If you do not need to include special characters, the choice of encoding is not important.<br />

A PDF document is not like an HTML document or a word processor document.<br />

Text does not by default start at the top left <strong>and</strong> flow onto other lines as required.You<br />

need to choose where to place each line of text. As already mentioned, PDF uses points<br />

to specify locations.The origin (the x,y coordinate [0, 0]) is at the bottom-left corner of<br />

the page.<br />

Given that the page is 612 by 792 points, the point (50, 700) is about two-thirds of an<br />

inch from the left of the page <strong>and</strong> about one-<strong>and</strong>-one-third inches from the top.To set<br />

the text position at this point, you use<br />

pdf_set_text_pos($pdf, 50, 700);<br />

Finally, having set up the page, you can write some text on it.To add text at the current<br />

position using the current font, you use pdf_show().<br />

The line<br />

pdf_show($pdf,'Hello,world!');<br />

adds the text “Hello World!” to the document.<br />

To move to the next line <strong>and</strong> write more text, you use pdf_continue_text().To<br />

add the string “(says <strong>PHP</strong>)”, you use<br />

pdf_continue_text($pdf,'(says <strong>PHP</strong>)');<br />

The exact location where this text will appear depends on the font <strong>and</strong> size selected.<br />

If, rather than lines or phrases, you are using contiguous paragraphs, you might find<br />

the function pdf_show_boxed() more useful. It allows you to declare a text box <strong>and</strong><br />

flow text into it.<br />

After you have finished adding elements to a page, you need to call pdf_end_page()<br />

as follows:<br />

pdf_end_page($pdf);

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

Saved successfully!

Ooh no, something went wrong!