0

I am trying to display the base64 string in aspx page. I am using the below code:

System.Web.UI.WebControls.Image imgNew = new System.Web.UI.WebControls.Image();
 imgNew.ImageUrl = string.Format("data:application/jpeg;base64,{0}", Convert.ToString(base64String));

this only works for the base64string for the jpeg formats. for the base64string of the pdf the image is not displaying properly. Can anyone help me? Thanks in advance.

Programmer
  • 657
  • 4
  • 9
  • 21
  • Possible duplicate of [Base 64 to image and pdf in c#](https://stackoverflow.com/questions/52328836/base-64-to-image-and-pdf-in-c-sharp) – Access Denied Sep 17 '18 at 04:08
  • [Try This One I'll think it will help you](http://stackoverflow.com/questions/17108278/display-asp-net-generated-pdf-byte-to-web-page-without-saving-the-file) – Antony Raj Sep 17 '18 at 04:11
  • Try this one it will help you and the sample code is given in link[code here](https://stackoverflow.com/questions/17108278/display-asp-net-generated-pdf-byte-to-web-page-without-saving-the-file) – Antony Raj Sep 17 '18 at 04:13
  • 1
    Image control cannot display PDF file. Try to convert pdf to image. https://social.msdn.microsoft.com/Forums/vstudio/en-US/60986d1b-2832-4413-8e8a-8290c196ffec/converting-pdf-file-to-an-jpeg-image?forum=csharpgeneral – Access Denied Sep 17 '18 at 04:30
  • by using `Response.ContentType = "application/pdf"; Response.AddHeader("content-length", outputPDF.Length.ToString()); Response.BinaryWrite(outputPDF);` I am able to see as a PDF . **But I am no aware of styling the PDF (need to border the contents)** – Programmer Sep 17 '18 at 05:16
  • Do you want to display pdf in the img tag?!! or create download link? – AmirNorouzpour Sep 17 '18 at 06:07
  • Display display pdf in the img tag – Programmer Sep 17 '18 at 06:24
  • 1
    you must use embed tag not img tag!! [link](https://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html) – AmirNorouzpour Sep 17 '18 at 06:28

1 Answers1

0

Convert the byte[] to Base64 using,

string base64PDF = System.Convert.ToBase64String(outputPDF, 0, outputPDF.Length);
Antony Raj
  • 71
  • 10