Hello, how are you?
I must access a PDF inside an object and show it with the PDF Viewer. I know that, having a URL, it's possible to do it using the DocumentPath property.
However, I don't have a URL for the document I want to show. It is stored as a byte[] property inside the object that I'm accessing in the property "DocumentoAnexado1" (Translation: AttachedFile1):
I didn't see (or understand) any option for this case in the documentation.
Is it possible to use this object as a source for the PDF in the PDF Viewer?
Thanks,
Hi Edurado,
Yes, it is possible to use the object as a source for the PDF in the PDF Viewer.
Kindly find the document for it below - https://blazor.syncfusion.com/documentation/pdfviewer/how-to/load-pdf-document-dynamically.
If you still have any concerns kindly revert to us, We are here to assist you.
Regards,
Visvesvar K V
I tried to do as the example shows, but I got an error related to 'm_memoryCache'
This is how the PDF is stored inside the object. It's inside the byte[] property "DocumentoAnexado1"
What am I doing wrong?
Hi Edurado,
We were unable to reproduce the reported issue with the provided
details. We have shared the sample in which we have tried to reproduce the
issue in the below link,
https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorSample-1252046910
Kindly try this and revert to us with modified sample, code snippet,
replication procedure and more details about the reported issue if you have any
concerns. This will be helpful for us to analyze further and provide the
details.
Regards,
Visvesvar K V
Hello, Visvesvar!
In your sample, you have the file in your project and you can load it's url. You can turn it into byte[] array for the example too.
In my case, I only have the byte[] array. I think my mistake is related to it, maybe I'm not converting the byte[] property into something the component can work with.
I created a new project with the latest version of the components and with the byte[] that I'm trying to use.
The samples are in the PDF Viewer Link, and when I click on it, the error messages about m_memoryCache appears
I hope you can see what is the problem
Hi Edurado,
Thank you for your update and sample.
We were able to reproduce the reported issue “Exception occurs while trying to load as byte array” and suspect this to be a defect. We will analyze
further on this and update you with more details on November 01, 2022.
Regards,
Visvesvar K V
Thank you very much!
I'l be waiting
Regards,
Hi Edurado,
Thank you for your patience.
In the given sample you have tried to render both the “SfPdfViewerServer” and “SfPdfViewer” components in the same application. Kindly use either the WASM app or the Server app. So kindly use “SfPdfViewerServer” for the serverside application and “SfPdfViewer” for the web assembly application.
Note :
Kindly find the details below.
Document doc = new Document
{
file = "JV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TF8.GetBytes(doc.file); get the file from the object (I'm turning it into a byte[] array, I'm trying to reproduce my scenario)
base64String = Convert.ToBase64String(byteArray); convert the byte[] into 64string
await component.LoadAsync("data:application/pdf;base64," + base64String, null);
}
2. We have tried the below code it is working
properly. Kindly modify the below code snippet. Kindly validate the data once.
public async void LoadFile()
{
byte[] byteArray;
string base64String;
byteArray = System.IO.File.ReadAllBytes("wwwroot/Data/PDF_Succinctly.pdf");
base64String = Convert.ToBase64String(byteArray);
await component.LoadAsync("data:application/pdf;base64," + base64String, null); // load the file with the component
}
Kindly use the below URL to test whether base 64 contains the proper file information.
https://base64.guru/converter/decode/pdf
Kindly revert to us if you still have any queries. We are here to assist you.
Regards,
Visvesvar K V
Hello, how are you?
Thank you for the answer, guess I will not be able to use the byte[] array for the job.
Is it possible to use a XML string, then?
I saw this article https://www.syncfusion.com/kb/6194/how-to-convert-xml-to-pdf-in-c-and-vb-net
but the library is already deprecated. Is there any tool available for this?
Kindly update the XML data that you have. Also please share the sample that you try to load the document from XML.
I'm sending the same sample, now with a XML property. It should look like this:
We could not able to find any PDF document information with the XML data that you have shared.
We could not save the PDF document as XML format. In the below example, we just show the XML information available in the XML file as a PDF document like converting the HTML page to a PDF document.
https://www.syncfusion.com/kb/6194/how-to-convert-xml-to-pdf-in-c-and-vb-net
So suggest you keep your PDF documents as base64 or byte array. But the base 64 or byte array you have shared already was corrupted. So could you please provide the information like code snippets or samples to know how the base or byte array was converted from the PDF document? Or please use the below code snippet that we have already shared to convert your PDF document as base64 string.
public async void LoadFile()
{
byte[] byteArray;
string base64String;
byteArray = System.IO.File.ReadAllBytes("wwwroot/Data/PDF_Succinctly.pdf");
base64String = Convert.ToBase64String(byteArray);
await component.LoadAsync("data:application/pdf;base64," + base64String, null); // load the file with the component
}