Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ domainurl: ##DomainURL##

# Load Large PDF Files in Blazor PDF Viewer

This section explains how to load and render **large PDF files (up to approximately 1 GB)** efficiently using the Syncfusion Blazor PDF Viewer. It also covers the recommended configurations required to achieve stable and responsive performance while working with large documents.
This section explains how to load and render **large PDF files (up to approximately 1 GB)** efficiently using the Blazor PDF Viewer. It also covers the recommended configurations required to achieve stable and responsive performance while working with large documents.

## Why Large PDFs Require Special Handling

Expand All @@ -35,8 +35,6 @@ With proper configuration, the Blazor PDF Viewer can:

N> Large PDF support depends on enabling chunk-based processing (refer [EnableChunkMessages](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_EnableChunkMessages)) and proper server configuration. The actual supported size may vary based on browser memory limits, server settings, and system resources.

---

## Best Practices for Loading Large PDFs

### 1. Enable Chunk‑Based Processing
Expand All @@ -45,27 +43,36 @@ Chunk-based processing is **mandatory** for loading large PDF files in the Blazo

Refer to the following FAQ to configure chunk-based processing:

- [How to process Larges files using EnableChunkMessages](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/faqs/how-to-processing-large-files-without-increasing-maximum-message-size)
- [How to process Large files using EnableChunkMessages](../faqs/how-to-processing-large-files-without-increasing-maximum-message-size)

Ensure that:

- The server supports **HTTP range requests**
- Chunk processing is enabled as documented
- Connection buffer limits are configured correctly

### 2. Load Large PDFs Using `DocumentPath`
### 2. Load Large PDFs Using DocumentPath

For large documents, it is recommended to load the PDF using the [DocumentPath](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_DocumentPath) property.

Using `DocumentPath` helps:

- Initiate chunk-based requests immediately
- Avoid loading the entire document into memory
- Avoid buffering the entire file in client memory
- Improve stability and loading behavior for large files

This approach is suitable for PDFs hosted on servers, secured APIs, or cloud storage endpoints.

---
Example usage:

```cshtml
@using Syncfusion.Blazor.SfPdfViewer

<SfPdfViewer2 DocumentPath="https://your-server/large-file.pdf"
EnableChunkMessages="true"
Height="100%"
Width="100%" />
```

### 3. Optimize Network and Performance Configuration

Expand All @@ -75,29 +82,29 @@ Proper network configuration plays a critical role in rendering large PDFs.

Configuring a sufficient connection buffer size helps prevent interruptions while loading large documents:

- [How to increase connection Buffer size](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/faqs/how-to-increase-connection-buffer-size)
- [How to increase connection buffer size](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/faqs/how-to-increase-connection-buffer-size)

#### Use CDN for Improved Performance

Using CDN resources reduces script download time and improves viewer initialization performance:

- [How to improve performance using CDN](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/faqs/how-to-improve-performance-using-cdn)

---

### 4. Reduce System Resource Load

Rendering large PDF files also depends on available system resources.

For the best experience:
For the best experience, follow these steps:

- Close unused applications
- Minimize open browser tabs
- Avoid running multiple heavy tasks in parallel
- Do not open multiple large PDFs at the same time
1. Close unused applications.
2. Minimize open browser tabs.
3. Avoid running multiple heavy tasks in parallel.
4. Avoid opening multiple large PDFs at the same time.
5. Verify that adequate system memory and CPU are available before loading the file.

Ensuring adequate system memory and CPU availability helps maintain smooth rendering and interaction.

## See Also

- [Load and Save Sample](https://github.com/SyncfusionExamples/blazor-pdf-viewer-examples/tree/master/Load%20and%20Save)
- [Load a Password-Protected PDF](./load-password-pdf)
- [Getting started with SfPdfViewer in a Blazor Web App](../getting-started/web-app)
- [Load and Save Sample](https://github.com/SyncfusionExamples/blazor-pdf-viewer-examples/tree/master/Load%20and%20Save)
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,72 @@ domainurl: ##DomainURL##

# Load a Password-Protected PDF in Blazor

This article explains how to open password-protected PDF files in the Syncfusion Blazor PDF Viewer. The viewer supports both userinteractive loading (Open File dialog) and programmatic loading using APIs.
This article explains how to open password-protected PDF files in the Blazor PDF Viewer. The viewer supports both user-interactive loading (the built-in **Open File** dialog) and programmatic loading using APIs.

## 1. Opening a Password-Protected PDF Using the **Open File** Dialog
## Opening a Password-Protected PDF Using the **Open File** Dialog

When the user selects a password-protected PDF using the builtin **Open File** option:
When the user clicks the built-in **Open File** button in the PDF Viewer toolbar and selects a password-protected PDF:

- The viewer detects that the document is encrypted
- The viewer detects that the document is encrypted on the server side

![Open PDF Document](../../react/images/open-pdf.png)
![Open PDF Document](../images/open-pdf.png)

- A **password input popup** is automatically displayed

![Password Protected Pop-up](../../react/images/password-popup.png)
![Password Protected Pop-up](../images/password-popup.png)

- The user enters the password

- The document is decrypted and loaded

No additional configuration or code is required.
No additional configuration or code is required. This approach works for all password-protected PDFs opened locally by the user.

## Opening a Password-Protected PDF Programmatically

This approach works for all password-protected PDFs opened locally by the user.
Use the programmatic APIs when the password is known in advance or when the document is hosted on a server. The viewer supports both the `LoadAsync` overloads and the `DocumentPath` property.

## 2. Opening a Password-Protected PDF Programmatically
### Load the Document Using `LoadAsync`

If you load a password-protected PDF from a URL or through custom logic, the viewer provides two behaviors depending on how the file is loaded.
The [`LoadAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_LoadAsync_System_Byte___System_String_) method accepts a password parameter. The two supported overloads are:

### 2.1 Load the Document Using `LoadAsync(byte[] bytes, string password = null)`
- `LoadAsync(byte[] bytes, string password = null)` — pass the PDF as a byte array
- `LoadAsync(string document, string password = null)` — pass a URL or server-relative path

You can directly pass the password in the [`load`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_LoadAsync_System_Byte___System_String_) method:
**Example (byte array):**

```cs
@using Syncfusion.Blazor.SfPdfViewer
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.SfPdfViewer

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

@code{
@code {
SfPdfViewer2 Viewer;

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

- If the password is correct → the PDF loads immediately
- If the password is incorrect → the viewer displays the incorrect password popup
- If no password is provided → the password popup is shown automatically
N> The password parameter is consumed for the current load operation only and is not cached across re-renders. If the document is reloaded, supply the password again.

**Outcomes**

| Password state | Result |
|---|---|
| Correct | The PDF loads immediately |
| Incorrect | The viewer displays the incorrect password popup |
| Null or empty | The password popup is shown automatically |

This is useful when the password is known beforehand.
N> Handle incorrect-password events through the [`DocumentLoadFailed`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_DocumentLoadFailed) event to surface custom error messages.

### 2.2 Loading a Password-Protected Document's URL Using `documentPath`
### Loading a Password-Protected Document via `DocumentPath`

If the [`documentPath`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_DocumentPath) points to a password-protected PDF:
When the [`DocumentPath`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_DocumentPath) property points to a password-protected PDF, the viewer detects the encryption and prompts the user for the password automatically.

```cs
@using Syncfusion.Blazor
Expand All @@ -78,18 +87,23 @@ If the [`documentPath`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.
</SfPdfViewer2>

@code {
//Load URL for Passwrod-Protected Document in DocumentPath
public string DocumentPath { get; set; } = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
// URL for the password-protected sample document
public string DocumentPath { get; set; } = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly-password-protected.pdf";
}
```

N> Do not pass the password as a query string inside `DocumentPath`.

The viewer will:

- Detect encryption
- Detect encryption on the server
- Show the **password popup automatically**
- Allow the user to enter the correct password
- Then load the PDF
- Decrypt and load the PDF

![Password Protected Pop-up](../images/password-popup.png)

![Password Protected Pop-up](../../react/images/password-popup.png)
## See Also

N> No password should be passed inside `documentPath`.
- [Load Large PDF Files](./load-large-pdf)
- [Getting started with SfPdfViewer in a Blazor Web App](../getting-started/web-app)
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ domainurl: ##DomainURL##

# Pre-process PDF Document Before Displaying in Blazor PDF Viewer

This section explains why preprocessing is useful, what operations you can perform using the Syncfusion PDF Library and Blazor PDF Viewer, and how to load the processed document in the Blazor PDF Viewer.
This section explains why preprocessing is useful, what operations you can perform using the Syncfusion<sup style="font-size:70%">&reg;</sup> PDF Library and Blazor PDF Viewer, and how to load the processed document in the Blazor PDF Viewer.

## Why Preprocessing Is Needed
Preprocessing a PDF before sending it to the viewer helps you:
- Reduce file size and improve load time
- Merge multiple documents into one
- Extract only required pages for faster loading
- Flatten form fields and annotations for performance & security
- Apply branding elements such as watermarks or stamps
- **Reduce file size** — Compresses content to improve load time.
- **Merge multiple documents** — Combine several PDFs into a single file.
- **Extract only required pages** — Drop unused pages for faster loading.
- **Flatten form fields and annotations** — Improves rendering performance and prevents further editing.
- **Apply branding elements** — Such as watermarks or stamps.

These enhancements ensure a better, faster, and more controlled viewing experience.
Each enhancement maps directly to a measurable improvement in load time, rendering speed, or document control.

## Merge PDF Documents
### UI-Level Merging
Expand All @@ -31,11 +31,11 @@ You can visually merge pages in the **Organize Pages** UI inside the Blazor PDF
For more details, refer to [UI Interactions - Import Pages](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/organize-pages/ui-interactions#import-pages).

### Programmatically Merge PDFs
Using the Syncfusion PDF Viewer, you can merge documents before loading them into the viewer.
Using the Blazor PDF Viewer, you can merge documents before loading them into the viewer.

For more details, refer to [Programmatic Support - Import Pages](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/organize-pages/programmatic-support#import-pages).

N> You can then load the merged PDF into the viewer using a file path or stream.
N> You can then load the merged PDF into the viewer using a file path, stream, or byte array.

## Extract Pages
### UI-Level Extraction
Expand All @@ -60,15 +60,15 @@ For more details, refer to [Programmatic Support - Export Pages](https://help.sy

Use the following code-snippet when you want uploaded PDFs to be flattened before they are loaded into the viewer.

```cs
```csharp
@page "/"
@using Syncfusion.Blazor
@using Syncfusion.Blazor.SfPdfViewer
@using Syncfusion.Pdf
@using Syncfusion.Pdf.Parsing

<SfPdfViewer2 Height="600px" Width="100%" @ref="Viewer"><PdfViewerEvents Created="OnCreated"></PdfViewerEvents></SfPdfViewer2>
@code{
@code {
private SfPdfViewer2? Viewer;
async Task OnCreated()
{
Expand Down Expand Up @@ -111,6 +111,8 @@ The Blazor PDF Viewer toolbar allows users to:

### Programmatically Add a Watermark

The following example loads an existing PDF, draws a watermark image on every page using `PdfGraphics`, and then reloads the result into the viewer. The image is loaded from a file in `wwwroot` and converted to a `byte[]` — the recommended approach over hard-coding base64.

```csharp
@page "/"
@using Syncfusion.Blazor
Expand Down Expand Up @@ -171,21 +173,25 @@ You can load the processed PDF using a remote URL, stream, or byte array and bas

### Load From Remote URL

Refer to the Syncfusion Blazor PDF Viewer documentation for loading PDF from Remote URL. For more details, visit [Load PDF Document from Remote URL](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/opening-pdf-file#opening-a-pdf-from-remote-url).
Refer to the Blazor PDF Viewer documentation for loading PDF from Remote URL. For more details, visit [Load PDF Document from Remote URL](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/opening-pdf-file#opening-a-pdf-from-remote-url).

https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/opening-pdf-file#opening-a-pdf-from-remote-url

### Load Using Stream or Byte Array

Refer to the Syncfusion Blazor PDF Viewer documentation for loading PDF from stream or byte array. For more details, visit [Load PDF Document from Stream](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/opening-pdf-file#opening-a-pdf-from-stream).
Refer to the Blazor PDF Viewer documentation for loading PDF from stream or byte array. For more details, visit [Load PDF Document from Stream](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/opening-pdf-file#opening-a-pdf-from-stream).

### Load Using base64 Data

Refer to the Syncfusion Blazor PDF Viewer documentation for loading PDF from base64 data. For more details, visit [Load PDF Document from base64 Data](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/opening-pdf-file#opening-a-pdf-from-base64-data).
Refer to the Blazor PDF Viewer documentation for loading PDF from base64 data. For more details, visit [Load PDF Document from base64 Data](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/opening-pdf-file#opening-a-pdf-from-base64-data).

## Additional Performance Tips

- **Render Multiple Pages While Scrolling:** Improve performance by rendering multiple pages during scrolling. For more details, refer to [How to render N pages while scrolling](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/faqs/how-to-render-n-pages-scrolling).
- **Improve Performance Using CDN:** Enhance viewer performance using a Content Delivery Network. For more details, refer to [How to improve performance using CDN](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/faqs/how-to-improve-performance-using-cdn).

## See Also

- [Load Large PDF Files](./load-large-pdf)
- [Load a Password-Protected PDF](./load-password-pdf)
- [Getting started with SfPdfViewer in a Blazor Web App](../getting-started/web-app)
Loading