Anubrij Chandra
Anubrij Chandra

Reputation: 1442

How to convert office file to image

I am searching from last two days but did not find any thing.

My requirement is to create a document viewer in my web application (C#.Net) and I don't want to use any third party tool for this. Can I convert the files in image or PDF or in any common formate which can be easly render on web page. I also can not use Introp object.

Any help will be highly appreciated

Upvotes: 4

Views: 3818

Answers (4)

Shivaji Varma
Shivaji Varma

Reputation: 682

You can use tools like smallpdf or OfficeToPDF to do that. Just integrate them into your application.

Small PDF(https://smallpdf.com/library-detail)

officetopdf (https://officetopdf.codeplex.com/)

Upvotes: 0

Corith Malin
Corith Malin

Reputation: 1525

You mention in one of your comments that you'd like to write all the code yourself but don't know where to start. Here's how I would go about it...

First, you'll need to familiarize yourself with the Microsoft Office Format specification. You can find that here (there's a link to the technical specification). Office documents are actually a .zip file with an XML file inside along with any binary data representing attachments. Just renamed a .docx file as .zip and you'll be able to open it up and see the XML and any other supporting documents inside (same is true for xlsx, etc...).

Then you'll need to become intimately familiar with either PDF or HTML, as your job now will be to convert the various Office document structure into PDF or HTML structure, being sure to respect page layout, margins, order, etc...

As others have said, this is a large task which is why third party tools exist today. Also, each third party toolset has it's limitation as this is really hard to "get right" in all situations and there will be edge cases that work for one document and not another (because maybe they didn't use Microsoft Word to save the .docx, maybe they used OpenOffice and OpenOffice interpreted the standard slightly differently...)

Upvotes: 4

Akhilesh
Akhilesh

Reputation: 121

I believe what you need is an intermediate representation of the documents which can be converted into an image for the viewer to display.

Lets me try to explain with the below diagram:

enter image description here

Upvotes: 2

Mikhail
Mikhail

Reputation: 9300

If you cannot use COM/Interop technologies in your solution, you can take a look at the specialized 3rd party options. I see that you prefer not to use them, however, there are no existing built-in solutions in the .NET Framework. Check out my answer in a similar thread that describes how to accomplish exactly the same task using 3rd party libraries (for example, DevExpress, since I have experience with it). In addition, take a look at the Documents demo, where you can see how to create images/thumbnails from different types of MS Office documents.

Upvotes: 3

Related Questions