If you want to process Office documents in .NET, for instance, if you use the DotImage AJAX Image Viewer and want to view a Word document, the easiest way is to use Office 2007 to do the heavy lifting. Here are instructions for doing that, but please read this KB about using Office on the serverside.

The easiest way to make an Office document readable by DotImage is to convert it into a PDF and then use our PDF Reader to read it. If you use Office 2007, download and install the Office Save as PDF Add-in to add this capability to Office, so that we can call it from .NET.

Once you do that, here's the code for converting a Word Doc to a PDF:

    private void Word2Pdf(

         string wordDocFile, string pdfDocFile)

    {

        object falseObj = false;

        object trueObj = true;

        object emptyStr = "";

        object missing = System.Reflection.Missing.Value;

 

        Microsoft.Office.Interop.Word.Application

              wordApp = null;

        try

        {

            wordApp = new

              Microsoft.Office.Interop.Word.Application();

            wordApp.Visible = false;

            object wordDocFileObj = wordDocFile;

            Microsoft.Office.Interop.Word.Document

              wordDoc = null;

            try

            {

                wordDoc = wordApp.Documents.Open(

                 ref wordDocFileObj,

                 ref falseObj,

                 ref trueObj,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing,

                 ref missing);

 

                wordDoc.ExportAsFixedFormat(
                  pdfDocFile,  

                  WdExportFormat.wdExportFormatPDF,

                  false,

                  WdExportOptimizeFor.

                     wdExportOptimizeForOnScreen,

                  WdExportRange.wdExportAllDocument,

                  -1, -1,  

                  WdExportItem.wdExportDocumentWithMarkup,

                  true, true,  

                  WdExportCreateBookmarks.

                     wdExportCreateNoBookmarks,

                  false, true, true, ref missing); 

            }

            finally

            {

                if (wordDoc != null)

                    wordDoc.Close(ref falseObj,

                      ref missing, ref missing);

                wordDoc = null;

            }

        }

        finally

        {

            if (wordApp != null)

                wordApp.Quit(ref falseObj,

                  ref missing, ref missing);

            wordApp = null;

        }

    }

Most of the work for doing this is to provide the right kind of automation objects to the Office API. 

You need to add a reference to Microsoft.Interop.Word, and add the following using statement:

using Microsoft.Office.Interop.Word;

 

The attached solution will show you how to read in Excel and PowerPoint into our web image viewer as well.