PDF Document Security in MAUI

PSPDFKit for MAUI offers developers control over document security when documents are displayed in the viewer.

Preventing Printing

It’s possible to enable or disable printing using the IsDisabled property of the PrintButton object:

var printButton = (PrintButton)PSPDFKitController.MainToolbar.
   ToolbarItems.Single(item => item is PrintButton);
printButton.IsDisabled = true;

To remove the print button from the toolbar, use the following code:

var printButton = PSPDFKitController.MainToolbar.ToolbarItems.First(
    item => item.GetType() == typeof(PrintButton));

PSPDFKitController.MainToolbar.ToolbarItems.Remove(printButton);

Preventing Exporting

You can prevent a user from using the export toolbar item to export PDFs by omitting it from the list of toolbar items:

var exportPDFButton = PSPDFKitController.MainToolbar.ToolbarItems.First(
    item => item.GetType() == typeof(ExportPDFButton));

PSPDFKitController.MainToolbar.ToolbarItems.Remove(exportPDFButton);

Protecting PDFs with a Password

To create a password-protected PDF from a document, follow these steps:

  1. Load the source document.

  2. Use the ExportDocumentAsync method to convert the source document to a password-protected PDF. This method takes IExportConfiguration as its parameter, which configures the conversion. For conversion to a password-protected PDF, update the Permissions object that you pass to the export method.

    • UserPassword takes a string value that specifies the user password. Users might have limited access to the document depending on how you configure user permissions with the PermissionFlags parameter.

    • OwnerPassword takes a string value that specifies the owner password. Owners have full access to the document.

    • PermissionFlags specifies what users can do with the document. For more information on setting user permissions, see Setting User Permissions below.

  3. Save the output document. The export method returns a byte[] that contains the output PDF document. You can then save the output PDF to a desired location. For more information on exporting documents, refer to the guides on saving a document.

The example below loads a PDF document and exports it to a PDF that can only be opened with the user password, and users can only view the document:

var document = await PDFView.Controller.LoadDocumentAsync("source.pdf");

var exportConfiguration = document.CreateExportConfiguration();
exportConfiguration.Permissions.UserPassword = "u$erp@ssw0rd";
exportConfiguration.Permissions.OwnerPassword = "u$ownerp@ssw0rd";

var outputDocument = await document.ExportDocumentAsync(exportConfiguration);

Setting User Permissions

Specify what users can do to a password-protected document with the PermissionFlags property. Using this flag, you can set the following permissions:

  • AnnotationsAndForms allows users to add or modify text annotations and fill in interactive form fields.

  • Assemble allows users to insert, rotate, or delete pages and create document outline items or thumbnail images.

  • Extract allows users to copy or otherwise extract text and graphics from the document.

  • ExtractAccessibility allows users to copy or otherwise extract text and graphics from the document using accessibility options.

  • FillForms allows users to fill in existing interactive form fields (including signature fields).

  • Modification allows users to modify the document in any way not covered by the other permissions settings.

  • PrintHighQuality allows users to print the document in high quality.

  • Printing allows users to print the document.