Load pdf from byte[] from component parameter like DocumentPath ? Or an event after component loaded

Hello,

Is there a way to load pdf from byte array with parameter like DocumentPath ?

I 'know that is possible to load pdf like this :

@using Syncfusion.Blazor.PdfViewerServer
@using Syncfusion.Blazor.Buttons

<SfButton @onclick="clicked">Load Document</SfButton>
<SfPdfViewerServer DocumentPath="@DocumentPath" Height="500px" Width="1060px" @ref="Viewer"></SfPdfViewerServer>

@code{
    SfPdfViewerServer Viewer;
    private string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";

    public void clicked()
    {
        byte[] byteArray = System.IO.File.ReadAllBytes("wwwroot/Data/Python_Succinctly.pdf");
        string base64String = Convert.ToBase64String(byteArray);
        Viewer.Load("data:application/pdf;base64," + base64String, null);
    }
}



But I want to load the pdf right now after the component loaded => there is an event after component loaded where I can load my byte array ?

Thanks,
Nicolas

2 Replies 1 reply marked as answer

VS Vasugi Sivajothi Syncfusion Team March 16, 2021 08:03 AM UTC

Hi Nicolas, 
 
 
Thanks for contacting Syncfusion support. 
 
 
We can load the document initially using Created event. Please refer to the below code snippet and sample, 
 
Code snippet: 
 
 
              <SfPdfViewerServer @ref="PdfViewer" Height="500px" Width="1060px"> <PdfViewerEvents Created="DocumentLoad"></PdfViewerEvents> </SfPdfViewerServer> 
@code{ 
    public SfPdfViewerServer PdfViewer { get; set; } 
 
    public void DocumentLoad() 
    { 
        byte[] byteArray = System.IO.File.ReadAllBytes("wwwroot/Data/PDF_Succinctly.pdf"); 
        string base64String = Convert.ToBase64String(byteArray); 
        PdfViewer.Load("data:application/pdf;base64," + base64String, null); 
    } 
 
} 
 
 
 
 
 
Please let us know if you have any concerns about this, 
 
 
Regards, 
Vasugi 


Marked as answer

NN Nicolas NOEL March 16, 2021 08:10 AM UTC

Hi Vasugi,

Thank you, it's works.

Have a nice day,
Nicolas

Loader.
Up arrow icon