예제 #1
0
        private string SaveAsHtmlForPdm(string filePath, Core.InternalBookmarkDomain firstDomain)
        {
            string tempCopyFileName = Path.ChangeExtension(Path.GetTempFileName(), FileExtension.Docx);
            string tempHtmlName     = Path.ChangeExtension(Path.GetTempFileName(), FileExtension.Html);

            Word.Application word   = null;
            Word.Document    newDoc = null;

            File.Copy(filePath, tempCopyFileName, true);

            try
            {
                word = new Microsoft.Office.Interop.Word.Application();

                word.DefaultWebOptions().Encoding = MsoEncoding.msoEncodingUTF8;

                newDoc = word.Documents.Open(tempCopyFileName, Visible: false, AddToRecentFiles: false, Encoding: MsoEncoding.msoEncodingUTF8);

                RemoveCustomXmlParts(newDoc);
                MakePdwWatermark(word, TemplateType.Pdm, firstDomain);

                newDoc.SaveAs(tempHtmlName, Word.WdSaveFormat.wdFormatFilteredHTML, AddToRecentFiles: false, Encoding: MsoEncoding.msoEncodingUTF8);
                ((Word._Document)newDoc).Close();
            }
            finally
            {
                ((Word._Application)word).Quit(Type.Missing, Type.Missing, Type.Missing);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(word);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(newDoc);

                File.Delete(tempCopyFileName);
            }

            return(tempHtmlName);
        }