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:
Alternatively, direct calls to generate specific document writers can be used, such as:
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:
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:
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:
Finally, the document writer itself can be freed in the usual fashion by calling fz_drop_document_writer: