2

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.

Prashan Fernando
  • 281
  • 4
  • 11
  • 1
    Why jpg? Jpeg creates severe graphical artifact on text (unless you use very high quality). Png should fit most documents much better. – CodesInChaos Jul 28 '11 at 21:46
  • 2
    Unless the files are < 2 pages DOC to PDF is probably the better way to go – Conrad Frix Jul 28 '11 at 21:58
  • Be aware that if a high-fidelity layout is required then there is no way around using Word (or SharePoint). – Dirk Vollmar Jul 28 '11 at 22:26
  • I've updated the question. Pls check that out – Prashan Fernando Jul 30 '11 at 06:40
  • do you want to generate images on the fly? Or can they be pre-prepared and cached. Also jpg is a poor choice for text. Png is what you want. – David Heffernan Jul 30 '11 at 06:52
  • It is a horrible idea to use Office Interop from ASP.NET or another server technology. These APIs were written for use in a desktop application, for automating Office (a suite of desktop applications). Server applications are different in many ways that make it a very, very bad idea to use Office Interop in them. It's also unsupported by Microsoft, and may violate your Office license. See [Considerations for server-side Automation of Office](http://support.microsoft.com/kb/257757) – John Saunders Dec 24 '14 at 17:51

4 Answers4

2

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)...

Yahia
  • 69,653
  • 9
  • 115
  • 144
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.

Shahzad Latif
  • 1,408
  • 12
  • 29
1

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);
            }
        }
    }
}
0

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.

Community
  • 1
  • 1
Justin
  • 84,773
  • 49
  • 224
  • 367