Opening/Closing a document

The simplest way to load a document is to load it from the local filing system:


\begin{lstlisting}
/*
fz_open_document: Open a PDF, XPS or CBZ document.
\par
O...
...ument *fz_open_document(fz_context *ctx, const char *filename);
\end{lstlisting}

For embedded systems, or secure applications, the use of a local filing system may be inappropriate, so an alternative is available whereby documents can be opened from a fz_stream. See Stream Stream for more details on fz_streams.


\begin{lstlisting}
/*
fz_open_document_with_stream: Open a PDF, XPS or CBZ docu...
..._stream(fz_context *ctx, const char *magic, fz_stream *stream);
\end{lstlisting}

Almost any data source can be wrapped up as a fz_stream; see Stream Stream for more details.

In common with most other objects in MuPDF, fz_documents are reference counted:


\begin{lstlisting}
/*
fz_keep_document: Keep a reference to an open document.
\...
...s.
*/
void fz_drop_document(fz_context *ctx, fz_document *doc);
\end{lstlisting}

Once the last reference to the document is dropped, all resources used by that document will be released, including those in the Store.