31.2 PDF Document

The first step in dealing with a PDF document is to get a handle to it. This is done by opening it as normal using fz_open_document to get a fz_document pointer. To ‘promote’ this to a pdf_document, we use the pdf_specifics call:

/* 
   pdf_specifics: down-cast a fz_document to a pdf_document. 
   Returns NULL if underlying document is not PDF 
*/ 
pdf_document *pdf_specifics(fz_context *ctx, fz_document *doc);

If pdf_specifics returns non-NULL, then you know that you are indeed dealing with a PDF format document.

Having a pdf_document pointer allows a series of new APIs to be called (see include/mupdf/pdf/document.h).

In terms of handling a PDF file via its constituent objects, one of the most useful is:

pdf_obj *pdf_trailer(fz_context *ctx, pdf_document *doc);

This obtains a pointer to a representation of the trailer dictionary object.