Frage

I'm working on some code which trying to convert a Word document to a swf file.

I do it this way:

  1. I convert the word document to PDF document by using the office component sevice
  2. I convert the PDF to swf by using swftools.

I did it on my computer (64-bit, Windows Server 2008 R2, Office 2010) and it works fine, but when I put it in server (64-bit, Windows server 2008 R2, Office2010), a 'Save As' dialog will show when the code is trying to close Word in program, and whether I click 'save' or 'cancel', it will throw the exception 'the file is readonly'. But actually, I didn't change the original file, I just opened it and saves it as a PDF document.

Here is the code 'convert Word to PDF':

bool ret = true;
        Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word.Document doc = null;
        object Unknown = Type.Missing;
        try
        {

            object Source = path;
            object Target = path.Substring(0, path.LastIndexOf(".")) + ".pdf";
            if (outpath != "")
                Target = outpath;
            object readOnly = true;
            object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
            doc = newApp.Documents.Open(ref Source, ref Unknown, ref readOnly,
                ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown,
                ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
            doc.SaveAs(ref Target, ref format,
                ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown,
                ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
        }
        catch (Exception e)
        {
            ret = false;
        }
        finally
        {
            if (doc != null)
            {
                doc.Close(ref Unknown, ref Unknown, ref Unknown);
                //dialog shows up here
            }
            newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
            GC.Collect();
        }

        return ret;

Any suggestions?

War es hilfreich?

Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top