Display pdf byte array as image in ASP.Net

Last Reply 10 months ago By dharmendr

Posted 11 months ago

Hi,

I use the code as shown on http://www.aspsnippets.com/Articles/Display-Byte-Array-as-Image-without-using-Generic-Handler-in-ASPNet.aspx#comments

It works great for .jpg files, but with a .pdf file it won't work. With a .pdf file no image is shown.

Is it possible to use this code for an .pdf file and if yes : how ?

This is my code:

byte[] pdfBytes = File.ReadAllBytes(@"c:\temp\test.pdf");

string pdfBase64 = Convert.ToBase64String(pdfBytes, 0, pdfBytes.Length);

Image1.ImageUrl = Convert.ToString("data:image;base64,") + pdfBase64;

I tried it also with "data:image\pdf and "data:image\bmp  but no result.

Thanks for your answer.

bye,

Marja

Results 1 - 5 of 7 12
Posted 11 months ago
Hi @marja,
Please try the following

Convert Image To ByteArray and display in webpage in ASP.Net

It might help you.

Cheers Andrea.

Posted 11 months ago

Hi Andrea,

Thanks for answering. Unfortunately it doesn't work, I get an "Parameter not valid".

FromStream is not available for .pdf it says.

I'm still looking for a solution.



Posted 10 months ago

Thanks for your answers, my conclusion is I cannot manage to show a pdf in an image without using third-party components like Ghostscript and others. So then the licensing thing is important; I have to ask management if it is allowed to use. Thanks for thinking with me.


Posted 10 months ago Modified on 10 months ago

There are no built-in functionality in the .Net framework for rendering a PDF file as a image. Only one solution is to use a third party library else it is not possible.

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html