Raster Image Export#

An application developer can export a document’s pages into raster image format by invoking the MuPDF library directly, opening the document and processing the resulting pages into a raster image file sequence.

Loading MuPDF without a UI#

To load the MuPDF library and use it directly an application developer should import mupdfdk and request a document load as follows:

import mupdfdk

var mupdfdkLib:MuPDFDKLib?

func processDocument(_ docPath:String) {
    let settings:ARDKSettings = ARDKSettings()
    mupdfdkLib = MuPDFDKLib.init(settings: settings)

    let fullPath:String = "\(FileManager.default.urls(for: .documentDirectory,
                          in: .userDomainMask).last?.path ?? "")/\(docPath)"

    let doc:MuPDFDKDoc = mupdfdkLib.doc(forPath: fullPath,
                    of: MuPDFDKDoc.docType(fromFileExtension: docPath)) as! MuPDFDKDoc

    doc.successBlock = {
        /// See iOS Sample App
    }

    doc.errorBlock = {(error:ARDKDocErrorType?) in

    }

    doc.loadDocument()

}

Upon document load completion an application developer should create an asynchronous task in the successBlock to render pages as bitmaps using the bitmapAtSize method of MuPDFDKDoc (the document instance) against the document’s MuPDFDKPage page instances. See the iOS Sample app and the ConvertToPNGSample folder reference for a full example.


This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at artifex.com or contact Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, CA 94129, USA, for further information.Discord logo