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.

Example 10-12. Using bookmarks and thumbnails (continued)<br />

pdf_begin_page($p,595,842);<br />

$top = pdf_add_bookmark($p, "Countries");<br />

$im = pdf_open_png($p, "fr-flag.png");<br />

pdf_add_thumbnail($p, $im);<br />

pdf_close_image($p,$im);<br />

$font = pdf_findfont($p,"Helvetica-Bold","host",0);<br />

pdf_setfont($p, $font, 20);<br />

pdf_add_bookmark($p, "France", $top);<br />

pdf_show_xy($p, "This is a page about France", 50, 800);<br />

pdf_end_page($p);<br />

pdf_begin_page($p,595,842);<br />

$im = pdf_open_png($p, "nz-flag.png");<br />

pdf_add_thumbnail($p, $im);<br />

pdf_close_image($p,$im);<br />

pdf_setfont($p, $font, 20);<br />

pdf_add_bookmark($p, "Denmark", $top);<br />

pdf_show_xy($p, "This is a page about New Zealand", 50, 800);<br />

pdf_end_page($p);<br />

pdf_close($p);<br />

$buf = pdf_get_buffer($p);<br />

$len = strlen($buf);<br />

header("Content-Type:application/pdf");<br />

header("Content-Length:$len");<br />

header("Content-Disposition:inline; filename=bm.pdf");<br />

echo $buf;<br />

pdf_delete($p);<br />

?><br />

The thumbnails generated by Example 10-12 are shown in Figure 10-14.<br />

Links<br />

pdflib supports functions that specify a region on a page that, when clicked on, takes<br />

the reader somewhere else. The destination can be either another part of the same<br />

document, another PDF document, some other application, or a web site.<br />

The pdf_add_locallink( ) function adds a local linkto another place within the current<br />

PDF file:<br />

pdf_add_locallink(pdf, llx, lly, urx, ury, page, zoom);<br />

All links in PDF files are rectangular. The lower-left coordinate is (urx,ury) and the<br />

upper-right coordinate is (urx,ury). Valid zoom values are "retain", "fitpage",<br />

"fitwidth", "fitheight", and "fitbbox".<br />

The following call defines a 50 × 50 area that, if clicked, takes the reader to page 3<br />

and retains the current zoom level:<br />

pdf_add_locallink($p, 50, 700, 100, 750, 3, "retain");<br />

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

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Navigation | 257

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

Saved successfully!

Ooh no, something went wrong!