public void Generate(IPriceList priceList, FileInfo template, string outputFileName)
        {
            lock (WordApplication.SyncRoot)
            {
                WordApplication application = WordApplication.Instance;

                try
                {
                    WordDocument document = application.OpenDocument(template.FullName);
                    _replacements.Apply(document.Content, priceList);
                    foreach (WordSection section in document.Sections)
                    {
                        foreach (var header in section.Headers)
                        {
                            _replacements.Apply(header.Range, priceList);
                        }
                        foreach (var footer in section.Footers)
                        {
                            _replacements.Apply(footer.Range, priceList);
                        }
                    }
                    document.Content.UpdateFields();
                    document.SaveAs(outputFileName, WdSaveFormat.wdFormatPDF);
                    document.Close(false);
                }
                finally
                {
                    application.Quit(false);
                }
            }
        }
Exemplo n.º 2
0
        public string SnapshotWordDocument(HttpFile httpFile)
        {
            string documentFileName = TempUpload(httpFile);
            string dirName          = CreateGuidDirectory();

            var wordApplication = new WordApplication();
            var wordDocument    = wordApplication.OpenDocument(documentFileName);

            wordDocument.SnapshotPages(dirName);
            wordDocument.Close();
            wordApplication.Quit();

            return(dirName);
        }
Exemplo n.º 3
0
        public void Snapshot(Uri uri, string fileName)
        {
            var wordApplication = new WordApplication();
            var wordDocument    = wordApplication.OpenDocument(fileName);
            var buildPath       = this.CreateTempDirectory();

            wordDocument.SnapshotPages(buildPath);
            wordDocument.Close();
            wordApplication.Quit();

            if (this.SendResponse(uri, buildPath))
            {
                Directory.Delete(buildPath, true);
                File.Delete(fileName);
            }
        }
Exemplo n.º 4
0
        public string ConvertWordToHtml(HttpFile httpFile)
        {
            string pageBaseName = ConfigurationManager.AppSettings.Get("page");

            string documentFileName = TempUpload(httpFile);
            string dirName          = CreateGuidDirectory();
            string pageFileName     = Path.Combine(dirName, pageBaseName);

            var wordApplication = new WordApplication();
            var wordDocument    = wordApplication.OpenDocument(documentFileName);

            wordDocument.FixPageBreaks();
            wordDocument.SaveAsHtml(pageFileName);
            wordDocument.Close();
            wordApplication.Quit();

            return(dirName);
        }