How can I help you?
Get PDF document data from Blazor SfPdfViewer2
14 Oct 20251 minute to read
Use the GetDocumentAsync method of the SfPdfViewer2 component to retrieve the currently loaded PDF document as a byte array, including user edits, annotations, and form field data.
The following example retrieves the current document data and then reloads the same document into the viewer.
@using Syncfusion.Blazor.SfPdfViewer
@using Syncfusion.Blazor.Buttons
<SfButton @onclick="retrieve">Retrieve Document</SfButton>
<SfButton @onclick="load">ReloadRetrievedDocument</SfButton>
<SfPdfViewer2 @ref="@viewer"
DocumentPath="@DocumentPath"
Height="100%"
Width="100%">
</SfPdfViewer2>
@code
{
SfPdfViewer2 viewer;
private string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
byte[]? save;
public async void retrieve()
{
//Gets the loaded PDF document
save = await viewer.GetDocumentAsync();
}
public async void load()
{
//Converts the byte array into base64 string.
string base64String = Convert.ToBase64String(save);
//Loads the PDF document from the specified base64 string.
await viewer.LoadAsync("data:application/pdf;base64," + base64String, null);
}
}