Export Pdf as byte[]

I'm using Blazor server and I'm loading succesufully a Pdf from disk into a SfPdfViewer 

After that I added successfully some annotations to add an image and a signature

Then I used these lines to export the pdf fields and fill them with my data and it works perfectly

            dictionary = await Viewer.ExportFormFieldsAsObjectAsync();

            Dictionary<string, string> dati = SchedeService.PdfContratto(schedascelta, filiale, swstampa.Checked ? "eng" : "ita", dictionary, pagine);

            await Viewer.ImportFormFieldsAsync(dati);


How can I export the complete pdf from the Viewer as a byte [] ?

Thanks


1 Reply

VS Venkada Subramanian Durai Syncfusion Team July 23, 2025 03:21 PM UTC

Hi Walter Martin,


Thank you for the update. You can get the byte array of the loaded document in the PDF Viewer by using the GetDocumentAsync API. This will return the byte array, which you can use for your application needs. We have attached a sample demonstrating how to use this API. Please check whether it meets your requirements and let us know if you have any queries.

Code snippet:


async Task GetPdf()
{

     if(Viewer != null)

     {

         byte[] pdfBytes = await Viewer.GetDocumentAsync();

     }
}


Regards,
Venkada Subramanian D


Attachment: Net8Server_f36c23cc.zip

Loader.
Up arrow icon