public void PublishFile(string sourceFilePath, string destinationFilePath, IPDFPublisherOptions options = null, object officeApplicationObject = null) { CheckLicense(); if (!Path.IsPathRooted(sourceFilePath)) throw new ArgumentException("The source file path is not an absolute path", "sourceFilePath"); if (!Path.IsPathRooted(destinationFilePath)) throw new ArgumentException("The destination file path is not an absolute path", "destinationFilePath"); if (!File.Exists(sourceFilePath)) throw new ArgumentException("The source file does not exist", "sourceFilePath"); if (IsOfficeDocument(sourceFilePath)) { using (OfficeApplicationObjectProvider appProvider = new OfficeApplicationObjectProvider(officeApplicationObject, GetOfficeDocType(sourceFilePath))) { object oDoc = OfficeDocumentManager.Load(appProvider.GetApplicationObject(), sourceFilePath); try { PublishDocument(oDoc, destinationFilePath, options); } finally { OfficeDocumentManager.CloseDocument(oDoc); } } } else { PublishUsingOLEVerbs(sourceFilePath, destinationFilePath, options); RaiseActionAnalyticsEvent(); } }
/// <inheritdoc/> public void PublishDocument(object officeDocument, string destinationFilePath, IPDFPublisherOptions options = null) { m_impl.PublishDocument(officeDocument, destinationFilePath, options); }
/// <inheritdoc/> public void PublishFile(string sourceFilePath, string destinationFilePath, IPDFPublisherOptions options = null, object officeApplicationObject = null) { m_impl.PublishFile(sourceFilePath, destinationFilePath, options, officeApplicationObject); }
private void PublishWordDocument(object officeDocument, string destinationFilePath, IPDFPublisherOptions options) { using (PublisherObject ppo = new PublisherObject()) { ppo.Object.ReconstructHyperLinks = options.ReconstructHyperlinks; ppo.Object.PublishActiveWordDocument(destinationFilePath, officeDocument, options.PageRange, 0); } }
private void PublishPowerPointPresentation(object officeDocument, string destinationFilePath, IPDFPublisherOptions options) { using (PublisherObject ppo = new PublisherObject()) { if (string.IsNullOrEmpty(options.PageRange)) { ppo.Object.PublishWithPowerPoint(destinationFilePath, officeDocument); } else { int vFrom, vTo; ParsePageRange(options.PageRange, out vFrom, out vTo); ppo.Object.PublishWithPowerPoint(destinationFilePath, officeDocument, vFrom, vTo); } } }
public void PublishDocument(object officeDocument, string destinationFilePath, IPDFPublisherOptions options = null) { if (!Path.IsPathRooted(destinationFilePath)) throw new ArgumentException("The destination file path is not an absolute path", "destinationFilePath"); if (officeDocument == null) throw new ArgumentNullException("officeDocument"); if (options == null) options = new PDFPublisherOptions(); if (officeDocument is Microsoft.Office.Interop.Word.Document) { PublishWordDocument(officeDocument, destinationFilePath, options); } else if (officeDocument is Microsoft.Office.Interop.PowerPoint.Presentation) { PublishPowerPointPresentation(officeDocument, destinationFilePath, options); } else if (officeDocument is Microsoft.Office.Interop.Excel.Workbook) { PublishExcelWorkbook(officeDocument, destinationFilePath, options); } else { throw new ArgumentException("Not a supported Microsoft Office automation object", "officeDocument"); } // this is necessary because the print to pdf causes the system settings to change // which is handled as a threadmessage by the .net framework // and if we don't do events, the processing of the message doesn't finish, so the runtime is locked // so the finalizers don't run. Application.DoEvents(); RaiseActionAnalyticsEvent(); }
private void PublishUsingOLEVerbs(string sourceFilePath, string destinationFilePath, IPDFPublisherOptions options) { string contentType = GetContentType(sourceFilePath); if (string.IsNullOrEmpty(contentType)) throw new ArgumentException("The type of file specified has no associated application."); ProcessStartInfo psi = new ProcessStartInfo(sourceFilePath); List<string> verbs = new List<string>(psi.Verbs).Select(x => x.ToLower()).ToList(); if (verbs.Contains("printto")) { PrintViaPrintTo(destinationFilePath, psi); } else if (verbs.Contains("print")) { PrintViaPrintVerb(destinationFilePath, psi); } else { throw new InvalidOperationException("The specified file has no associated application which is capable of printing it."); } }