How can I help you?
How to load PDF from URL to server-side PDF viewer.
1 Oct 20251 minute to read
Syncfusion PDF Viewer supports loading PDF documents from remote URLs. For details, see Opening a PDF file. In scenarios where the document must be retrieved on the server (for example, to add authentication headers, avoid CORS issues, or protect the source URL), the following approach can be used to download the file server-side and load it into the viewer via a base64 data URI.
@using Syncfusion.Blazor.SfPdfViewer
<SfPdfViewer2 DocumentPath="@DocumentPath"
Height="100%"
Width="100%">
</SfPdfViewer2>
@code {
public string DocumentPath { get; set; }
protected override void OnInitialized()
{
string Url = "https://s3.amazonaws.com/files2.syncfusion.com/dtsupport/directtrac/general/pd/HTTP_Succinctly-1719682472.pdf";
System.Net.WebClient webClient = new System.Net.WebClient();
byte[] byteArray = webClient.DownloadData(Url);
DocumentPath = "data:application/pdf;base64," + Convert.ToBase64String(byteArray);
}
}