Getting Pages from a document

Once you have a laid out document, you presumably want to be able to do something with it. The first thing to know is how many pages it contains. This is achieved by calling fz_count_pages:


\begin{lstlisting}
/*
fz_count_pages: Return the number of pages in document
\p...
...ages.
*/
int fz_count_pages(fz_context *ctx, fz_document *doc);
\end{lstlisting}

For document types like images, they appear as a single page. If you forget to lay out a reflowable document, this will trigger a layout for a default size and return the required number of pages.

Once you know how many pages there are, you can fetch the fz_page object for each page required:


\begin{lstlisting}
/*
fz_load_page: Load a page.
\par
After fz_load_page is it ...
...e *fz_load_page(fz_context *ctx, fz_document *doc, int number);
\end{lstlisting}

The pages of a document with n pages are numbered from 0 to n-1.

In common with most other object types, fz_pages are reference counted:


\begin{lstlisting}
/*
fz_keep_page: Keep a reference to a loaded page.
\par
Doe...
...ceptions.
*/
void fz_drop_page(fz_context *ctx, fz_page *page);
\end{lstlisting}

Once the last reference to a page is dropped, the resources it consumes are all released automatically.