Save a PDF document to an array buffer in MAUI

Exporting a PDF to a byte[] can be done with a single API call to <IDocument>.ExportDocumentAsync():

try
{
    var exportConfiguration = _document.CreateExportConfiguration();
    // Update the configuration here.

    var exportedDocumentAsArrayBuffer = await _document.ExportDocumentAsync(exportConfiguration);
}
catch (Exception ex)
{
    // Handle the exception.
}

The resolved byte[] can be then handled as desired. For example, you can send it to your server or save it to local storage.

For more control over exporting documents, use IExportConfiguration. If you pass null instead, the default configuration will be used:

var exportOptions = _document.CreateExportConfiguration();
{
    ExcludeAnnotations = true,
    ExportForPrinting = true,
    ExportIncrementally = false,
    Flatten = true,
};

var exportedDocumentContent = await _document.ExportDocumentAsync(exportConfiguration);