show pdf from base64 or from local file directly

Hi everyone, I searched the various tutorials, videos, demos etc... I found loading files from local by manually selecting them from folders, files from embedded resources, from url via http but... I need to show a pdf file directly, received via httpclient in base64 format but I didn't find anything, I tried saving the file in the app cache and opening the file from the viewmodel passing the file name through the 'QueryProperty' but when the viewmodel is started I call a function loading the file but the file name is not seen... Any suggestions?

Thank you


1 Reply

AH Alex Harson James Henso Syncfusion Team November 3, 2023 07:34 AM UTC

Hi Angelo Fichera, 


We suspect that you are using the PDF viewer control to show the PDF documents"HttpClient" can be used to load the PDF using the URL.  

Code snippet: 

private async Task<Stream> DownloadPdfStream(string URL) 

{ 

    HttpClient httpClient = new HttpClient(); 

    HttpResponseMessage response = await httpClient.GetAsync(URL); 

    //Check whether redirection is needed 

    if ((int)response.StatusCode == 302) 

    { 

        //The URL to redirect is in the header location of the response message 

        HttpResponseMessage redirectedResponse = await httpClient.GetAsync(response.Headers.Location.AbsoluteUri); 

        return await redirectedResponse.Content.ReadAsStreamAsync(); 

    } 

    return await response.Content.ReadAsStreamAsync(); 

} 


We've attached a sample of how to load a PDF using a URL. We have used a PDF link for illustration purpose in the sample. Please use the sample with your own link. Please let us know whether the sample and code snippet meets your requirement. 


Regards, 

Alex Harson James H 


Attachment: SimpleSample_b282f500.zip

Loader.
Up arrow icon