Navigation

PDF provides several navigation features for PDF files. Bookmarks function as a table of contents for the document, and you can provide viewers with thumbnail images indicating what’s at the other end of each bookmark. In addition, any part of a PDF page can be linked to another part of the current PDF file, another PDF file, or a completely different file.

Bookmarks and Thumbnails

Bookmarks make it easy to quickly navigate through long PDF documents. You can create a bookmark with the pdf_add_bookmark( ) function, which returns a bookmark handle:

$bookmark = pdf_add_bookmark(pdf, text, parent, open);

The text parameter is the label that the user sees. To create a nested menu of bookmarks, pass a bookmark handle as the parent option. The current location in the PDF file (as it is being created) is the destination of the bookmark.

Bookmarks can have thumbnails associated with them. To make a thumbnail, load an image and call pdf_add_thumbnail( ):

pdf_add_thumbnail(pdf, image);

Example 10-12 creates a top-level bookmark named “Countries” and nests two bookmarks, “France” and “New Zealand”, under the “Countries” bookmark. It also creates a representative thumbnail image for each page. These thumbnails can be viewed in Acrobat Reader’s thumbnail panel.

Example 10-12. Using bookmarks and thumbnails

<?php $p = pdf_new( ); pdf_open_file($p); pdf_begin_page($p,595,842); $top = pdf_add_bookmark($p, "Countries"); $im = pdf_open_png($p, "fr-flag.png"); pdf_add_thumbnail($p, ...

Get Programming PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.