How to Convert doc to jpg in .net

雨燕双飞 提交于 2020-01-02 15:55:27

问题


How can i convert doc/docx files to jpgs in ASP.Net. I don't want to install MS Word in server & use interop lib.

Update My scenario is that I need to show Word document pages, page by page to the user in a web page like google docs viewer.


回答1:


Interop on server/ASP.NET scenario is not supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2.

There are some 3rd-party libs for this sort of thing without automation and with high-fidelity and several other features (for example from Aspose)...




回答2:


You may try Aspose.Words for .NET to convert DOC/DOCX to JPEG. It doesn't require MS Office to be installed, or Interop. IT is a .NET assembly which can be used easily in your .NET applications just like any other .NET assembly. It works on 32/64-bit systems seamlessly.

Disclosure: I work as developer evangelist at Aspose.




回答3:


try this:

using Spire.Doc;
using System.Drawing;
using System.Drawing.Imaging;

namespace Doc2Jpeg
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("test.doc");

            for (int i = 0; i < doc.PageCount; i++)
            {
                System.Drawing.Image image = doc.SaveToImages(i, Spire.Doc.Documents.ImageType.Metafile); 
                image.Save(string.Format("result-{0}.jpeg",i), ImageFormat.Jpeg);
            }
        }
    }
}



回答4:


If you are after a thumbnail image then you can use the Windows explorer thumbnails functionality to generate a thumbnail for a .docx file for you. Full details are on the Stack Overflow question C# get thumbnail from file via windows api.

I'm not sure what components you would need to have installed on the server (word viewer would almost certainly do though, possibly less than that).

If you want something more complex then I suspect you have a difficult task ahead of you.



来源:https://stackoverflow.com/questions/6866110/how-to-convert-doc-to-jpg-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!