1

I am working on Document Approval Workflow where the document is submitted for certain approvals. The type of the document can be xlsx/jpg/doc/pdf.

After getting Approvals, I need to Print the document along with the details of Approvals. I've created an aspx page for the same and Placed two divs, the first Div should display the Document which is being approved and the second div has the details of the approvals(who approved the document with date-time stamp).

I have placed the following code in First DIV:

 <img src="data:image;base64,<%=System.Convert.ToBase64String(binFile)%>" />

The File is coming from Database in Binary Format.

The above methodology is working great for Image attachments but How can I achieve the same for other file formats possibly xlsx or pdf

Is there any way I can convert data in PNG/JPG & then display it using the same methodology? How can I convert the upcoming Binary data into Image format?

I've gone through the following:

Convert Binary Data to Image

Alina Anjum
  • 1,178
  • 6
  • 30
  • 53
  • Doing this simply sets the data for the image tag to a base64 encoded binary string, which will work (as you observed) with images, but not with PDF files, or anything else for that matter. For that you'll need to convert the source file (PDF, doc...) to a JPG/ PNG and then do this, but then you're just displaying an image of the document which may or may not satisfy your desire. If not, you'll need to actually read the document and display the content – MindSwipe Jan 08 '20 at 06:59
  • @MindSwipe yes I know, how can I convert other formats to JPG/PNG? – Alina Anjum Jan 08 '20 at 07:06

1 Answers1

1

There is no global solution to convert any type of file to an image.

You need to implement some intermediary logic in c# before sending to html.

Example 1: for pdf conversion to image, check how to convert pdf files to image

Example 2: for doc conversion to image, check Convert Word file pages to jpg images using C#

You need one implementation per file type.

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61
  • Alright, I am going to try this. is there any way I can open an Excel or PDF in DIV? (without converting to image) – Alina Anjum Jan 08 '20 at 07:20
  • https://stackoverflow.com/questions/2740297/display-adobe-pdf-inside-a-div for a pdf. The excel spreadsheets need to be converted to some kind of table. – Athanasios Kataras Jan 08 '20 at 07:39