Beispiel #1
0
		private void PublishWithWord(IDocumentPublisher6 publisher, string sourceFilename, string destinationFilename)
		{
			if (null == publisher)
				return;

			OfficeApplicationCache officeApplicationCache = OfficeApplicationCache.Instance;
			Word._Application wordApplication = officeApplicationCache.GetHostApplication(FileType.WordDocument) as Word._Application;
			if (wordApplication == null)
			{
				return;
			}

			bool wasVisible = wordApplication.Visible;
			try
			{
				object document = officeApplicationCache.OpenDocument(sourceFilename, false, FileType.WordDocument);
				WordFieldsUnlinker unlinker = new WordFieldsUnlinker(document);
				unlinker.UnlinkFilenameFields();

				publisher.ReconstructHyperLinks = (bool) m_actionPropertySet[PdfActionStringTable.ReconstructHyperLinks].Value;
				publisher.PublishActiveWordDocument(destinationFilename, document, null, 0);
				officeApplicationCache.CloseDocument(document, true);	// true parameter (savechanges): previously false, but in some situations word still asks to save.
				// see VE3155, but basically where old style headers (as per our redline), and with word open, and there is a DMS. (Incomprehensible perfect storm!)
			}
			finally
			{
				wordApplication.Visible = wasVisible;
			}
		}
		public override string Print(WorkbookItem wi)
		{
			using (new WsActivationContext())
			{
				string destination = Workshare.Pdf.Combine.Coordinator.Utilities.GetTemporaryFileWithPdfExtension();
                
                OpenDocument(wi.TempCopy);

                try
                {					
                    WordFieldsUnlinker unlinker = new WordFieldsUnlinker(m_ActiveDocument);
                    unlinker.UnlinkFilenameFields();
                    Publisher.PublishActiveWordDocument(destination, m_ActiveDocument, null, 0);                    
                }                
                finally
                {
					// Once the document has been opened, make sure that we always try to close it
					// even if the printing throws an exception.
                    CloseDocument();                    
                }

				return destination;
			}
		}