Usage

As well as opening existing documents, MuPDF contains functions to allow the easy creation of new documents. The most general form of this functionality takes the form of the fz_document_writer interface.

A document writer is obtained by calling a generation function. The most general purpose one is:


\begin{lstlisting}
/*
fz_new_document_writer: Create a new fz_document_writer, ...
...tx, const char *path, const char *format, const char *options);
\end{lstlisting}

Alternatively, direct calls to generate specific document writers can be used, such as:


\begin{lstlisting}
fz_document_writer *fz_new_cbz_writer(fz_context *ctx, const ...
...writer(fz_context *ctx, const char *path, const char *options);
\end{lstlisting}

Once a fz_document_writer has been created, pages can be written to the document one at a time. The process is started by calling fz_begin_page:


\begin{lstlisting}
/*
fz_begin_page: Called to start the process of writing a p...
...ontext *ctx, fz_document_writer *wri, const fz_rect *mediabox);
\end{lstlisting}

This function returns a fz_device pointer that should be used to write the page contents to. This can be done by making a sequence of normal device calls (see Device Device) to paint the page with its content. One of the most common ways of doing this is by calling fz_run_page_contents on another open document. This therefore offers a quick mechanism for converting documents from one format to another.

Once the page contents have all been written, the page is finalized by calling fz_end_page:


\begin{lstlisting}
/*
fz_end_page: Called to end the process of writing a page ...
...
*/
void fz_end_page(fz_context *ctx, fz_document_writer *wri);
\end{lstlisting}

At this point, many formats will allow more pages to be written, simply by repeating the fz_begin_page, output, fz_end_page loop.

When all the pages have been written, the produced document can be finalized by calling fz_close_document_writer:


\begin{lstlisting}
/*
fz_close_document_writer: Called to end the process of wr...
...lose_document_writer(fz_context *ctx, fz_document_writer *wri);
\end{lstlisting}

Finally, the document writer itself can be freed in the usual fashion by calling fz_drop_document_writer:


\begin{lstlisting}
/*
fz_drop_document_writer: Called to discard a fz_document_...
...drop_document_writer(fz_context *ctx, fz_document_writer *wri);
\end{lstlisting}