diff --git a/docs/first_steps.rst b/docs/first_steps.rst index 7f8d2770..d5b0fb56 100644 --- a/docs/first_steps.rst +++ b/docs/first_steps.rst @@ -425,7 +425,7 @@ pages with :meth:`document.Document.copy()`. Finally, for ultimate control, .. [#] Pages in the same document do not always have the same size. -See the :ref:`Python API` for details. A simple examples: +See the :ref:`Python API` for details. A few random examples: .. code-block:: python @@ -435,6 +435,25 @@ See the :ref:`Python API` for details. A simple examples: document.copy(document.pages[::2]).write_pdf('odd_pages.pdf') document.copy(document.pages[1::2]).write_pdf('even_pages.pdf') +.. code-block:: python + + # Print the outline of the document. + # Output on http://www.w3.org/TR/CSS21/intro.html + # 1. Introduction to CSS 2.1 (page 2) + # 1. A brief CSS 2.1 tutorial for HTML (page 2) + # 2. A brief CSS 2.1 tutorial for XML (page 5) + # 3. The CSS 2.1 processing model (page 6) + # 1. The canvas (page 7) + # 2. CSS 2.1 addressing model (page 7) + # 4. CSS design principles (page 8) + def print_outline(bookmarks, indent=0): + for i, bookmark in enumerate(bookmarks, 1): + page = bookmark.destination[0] + print('%s%d. %s (page %d)' % ( + ' ' * indent, i, bookmark.label.lstrip('0123456789. '), page)) + print_outline(bookmark.children, indent + 2) + print_outline(document.make_bookmark_tree()) + URL Fetchers ~~~~~~~~~~~~