Password-protected documents

14 Oct 20251 minute to read

Some PDFs require a password to open. When such a document is loaded in the viewer, the following behavior applies:

  • A password prompt appears if the document requires an password.

The viewer displays a password prompt UI when a protected document is opened.

Desktop password prompt:

Blazor PDF Viewer desktop password prompt

Mobile password prompt:

Blazor PDF Viewer mobile password prompt

  • If the correct password is provided, the document loads and becomes viewable per the document’s permissions.
  • If the password is incorrect, the viewer shows an error and continues to prompt until a valid password is entered or the operation is canceled.

Invalid password error in desktop:

Blazor PDF Viewer desktop password error

Invalid password error in Mobile:

Blazor PDF Viewer mobile password error

  • If the operation is canceled, the document is not loaded.

Load the password-protected document programmatically

Use the LoadAsync method to load a PDF from a file path, URL, or base64 data at runtime. Pass the password as the second parameter.

@using Syncfusion.Blazor.SfPdfViewer
@using Syncfusion.Blazor.Buttons

<SfButton @onclick="clicked">Load Document</SfButton>
<SfPdfViewer2 Height="100%" Width="100%" @ref="Viewer">
</SfPdfViewer2>

@code{
    SfPdfViewer2 Viewer;

    public async void clicked()
    {
        await Viewer.LoadAsync("wwwroot/pdf-succinctly-password-protected.pdf", "password");
    }
}

View sample in GitHub.

See Also