- Document and page loading indications
- Document source types
- Unload a document
- Opening a PDF document with annotations
- Check other PDF opening options
Contact Support
Open a Document in .NET MAUI PDF Viewer (SfPdfViewer)
The SfPdfViewer allows you to open PDF documents from various sources, like local storage or URLs. It also lets you view password-protected documents.
This section walks you through the loading and unloading of documents in SfPdfViewer and handling the load-specific events.
Document and page loading indications
The SfPdfViewer displays a built-in ActivityIndicator (loading indicator) under the following scenarios to indicate if there are any lengthy loadings.
-
At the document
– To indicate that the document is loading -
At the pages
– To indicate that the page content is loading.
To customize the appearance of the loading indicators, please refer to this section.
Document source types
The document source types accepted by the SfPdfViewer are Stream
and byte[]
. You can load the PDF document from a specified stream or bytes.
Load the document from stream
// Load the document from Stream
Stream pdfDocumentStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("GettingStarted.Assets.PDF_Succinctly.pdf");
PdfViewer.DocumentSource = pdfDocumentStream;
Load the document from Byte array
// Load the document from Byte array
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync("https://www.syncfusion.com/downloads/support/directtrac/general/pd/PDF_Succinctly1928776572");
PdfViewer.DocumentSource = await response.Content.ReadAsByteArrayAsync();
Unload a document
The SfPdfViewer allows you to unload and clear the resources occupied by the PDF document loaded using the UnloadDocument method, as shown below.
NOTE
- While changing or opening different documents on the same page, the previously loaded document will be unloaded automatically by the SfPdfViewer.
- And, if you are using multiple pages in your application, then make sure to unload the document from the SfPdfViewer while leaving the page that has it to release the memory and resources consumed by the PDF document that is loaded. The unloading of documents can be done by calling the UnloadDocument method.
//Unload the document from the PDF viewer.
PdfViewer.UnloadDocument();
Opening a PDF document with annotations
The .NET MAUI PDF Viewer does not currently support annotations comparable to Xamarin.Forms. However, it is possible to view the unsupported annotations in a non-interactive manner. To achieve this, provide the flattenOptions (an optional parameter) as Unsupported in the LoadDocument methods. See the following code example:
Stream pdfDocumentStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("GettingStarted.Assets.PDF_Succinctly.pdf");
FlattenOptions flattenOption = FlattenOptions.Unsupported;
// Loads the PDF document from the stream with flatten option to render unsupported annotations.
PdfViewer.LoadDocument(pdfDocumentStream, flattenOptions: flattenOption);
NOTE
- All the LoadDocument methods accept the flatten options parameter.
- Refer to this section for the upcoming annotation features in the SfPdfViewer.