-1

I have been searching for a way to convert word/excel byte array from sql server to a pdf file and then I want to show it to the view using <object> tag.

But I cant find any proper solution to this problem online because almost of them use non-free packages etc.

Does anybody know a way how to do it in c# without using other libraries ? If there is no way to do this please recommend me any package that is free and simple because I just want to use it for this purpose.

Refering to this question here I could use https://docs.google.com/gview?url=myDocUrl or https://view.officeapps.live.com/op/embed.aspx?src= but I dont know how to make them work with files saved in database as byte arrays and how to test them locally in visual studio.

If anybody knows how to use them with byte arrays please let me know as well.

Thanks in advance.

Rey
  • 3,663
  • 3
  • 32
  • 55

1 Answers1

1

First, you'll need to put your byte array into a format that the Office API can understand--probably save the byte array to a file on disk, then using the Word or Excel API library (Microsoft.Office namespace) to open the file and process it (such as saving it to a PDF file).

Russ
  • 4,091
  • 21
  • 32
  • I am trying to make a functionality where users can view their documents without the need to download them, so lets suppose I made the changes you said above. When should I delete them in order to not create junk files in server ? – Rey Oct 27 '17 at 18:30
  • That's for you to figure out. – Russ Oct 27 '17 at 18:32
  • This question was tagged as ASP.NET and ASP.NET MVC. Therefore the Office Interop libraries you're suggesting would be in appropriate. [Microsoft says not to do it](https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office). Your copy of Office likely isn't licensed to run on a server. The Interop libraries are not meant to be accessed from multiple threads at once. They're slow. And they often crash with hard to diagnose error messages. – mason Oct 27 '17 at 19:52
  • For the reasons I mentioned above, it's better to use a library that can natively manipulate Office files such as EPPlus, DocX, NPOI, Closed XML, Open XML SDK, Aspose etc. – mason Oct 27 '17 at 19:52