public override string Print(WorkbookItem wi) { using (new WsActivationContext()) { string destination = Utilities.GetTemporaryFileWithPdfExtension(); Outlook._Application app = new Outlook.Application(); Outlook._MailItem mailItem = app.Session.OpenSharedItem(wi.FileName) as Outlook._MailItem; try { if (mailItem == null) { return null; } Publisher.PublishWithOutlook(destination, mailItem); } finally { if (mailItem != null) { mailItem.Close(Outlook.OlInspectorClose.olDiscard); System.Runtime.InteropServices.Marshal.ReleaseComObject(mailItem); } } return destination; } }
private WorkbookItemInfo GetWorkbookItemInfo(WorkbookItem workbookItem) { return new WorkbookItemInfo() { InterimPdfPath = workbookItem.Pdf, OriginalFilePath = workbookItem.FileName, PageSelection = workbookItem.PageSelection }; }
public string PrintRange(WorkbookItem wi, PageSelection PageSelection) { IApplicationPrinterController controller = GetInstance(wi.TempCopy); try { return controller.PrintRange(wi, PageSelection); } catch (System.Exception) { throw; } finally { if (controller.Visible) controller.Visible = false; } }
public string Print(WorkbookItem wi) { IApplicationPrinterController controller = GetInstance(wi.TempCopy); try { return controller.Print(wi); } catch (System.Exception ex) { Logger.LogError(ex); throw; } finally { if (controller.Visible) controller.Visible = false; } }
public static bool RemovePassword(WorkbookItem workbookItem) { try { var requestForFile = workbookItem.DocumentId; var setForFile = workbookItem.Pdf; string password = Workshare.Pdf.Combine.Library.PasswordDialog.GetPassword(requestForFile); if (String.IsNullOrEmpty(password)) { // Todo: Replace with WsMessage.ShowMessage if (DialogResult.Retry == MessageBox.Show("No password given.\nClick Cancel to ignore this file and continue", "Warning", MessageBoxButtons.RetryCancel)) { return RemovePassword(workbookItem); } return false; } if (!Workshare.Pdf.Security.VerifyPassword(setForFile, password)) { // Todo: Replace with WsMessage.ShowMessage if (DialogResult.Retry == MessageBox.Show("This password is wrong.\nClick Cancel to ignore this file and continue", "Warning - Bad Password", MessageBoxButtons.RetryCancel)) { return RemovePassword(workbookItem); } return false; } Workshare.Pdf.Security.Remove(setForFile, password); return true; } catch(Exception ex) { Logger.LogError(ex); } return false; }
public override string PrintRange(WorkbookItem wi, PageSelection PageSelection) { throw new Exception("The method or operation is not implemented."); }
public override string Print(WorkbookItem wi) { using (new WsActivationContext()) { object vtMissing = System.Reflection.Missing.Value; object workbook = (HostApplication as Excel._Application).Workbooks.Open(wi.TempCopy, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, vtMissing); string destination = Workshare.Pdf.Combine.Coordinator.Utilities.GetTemporaryFileWithPdfExtension(); Publisher.PublishWithExcel(destination, workbook); (HostApplication as Excel._Application).Workbooks.Close(); Marshal.ReleaseComObject(workbook); return destination; } }
public void AddWorkbookItem(WorkbookItem info) { m_workbook.Add(info); }
private PowerPoint._Presentation FindOpenPresentation(WorkbookItem wi) { PowerPoint.Presentations presentations = (HostApplication as PowerPoint._Application).Presentations; foreach (PowerPoint.Presentation presentation in presentations) { if (presentation.FullName.Contains(wi.DisplayName)) return presentation; } return null; }
private void AddWorkbookItem(WorkbookItem item) { Logger.LogInfo("AddNewItems: " + item.FileName); Application.DoEvents(); int index = GetImageIndex(item.FileName); ListViewItem lvi = new ListViewItem(item.DisplayName, index); lvi.Tag = (object)item; if (listViewFiles.Items.Count > 0) { WorkbookItem wi = listViewFiles.Items[0].Tag as WorkbookItem; CopySecurityInformation(wi.PdfSecurityOptions, item); } ListViewItem.ListViewSubItemCollection subItems = new ListViewItem.ListViewSubItemCollection(lvi); ListViewItem.ListViewSubItem lviInner = new ListViewItem.ListViewSubItem(lvi, Properties.Resources.LBL_ALL_PAGES); lviInner.Name = SUBITEM_PAGERANGE; if (item.PageSelection != null) { if (!string.IsNullOrEmpty(item.PageSelection.Range)) { lviInner.Text = item.PageSelection.Range; } else { switch (item.PageSelection.Type) { case PageSelectionType.All: lviInner.Text = ALL_PAGES; break; case PageSelectionType.Odd: lviInner.Text = ODD_PAGES; break; case PageSelectionType.Even: lviInner.Text = EVEN_PAGES; break; } } lviInner.Tag = item.PageSelection.Type; } ListViewItem.ListViewSubItem lviInner2 = new ListViewItem.ListViewSubItem(lvi, Properties.Resources.LBL_ALL_PAGES); lviInner2.Name = SUBITEM_FILESIZE; lviInner2.Text = item.FileSize; ListViewItem.ListViewSubItem lviInner3 = new ListViewItem.ListViewSubItem(lvi, ""); lviInner3.Name = ""; subItems.Add(lviInner); subItems.Add(lviInner2); subItems.Add(lviInner3); ListViewItem lviCurrent = listViewFiles.Items.Add(lvi); lviCurrent.EnsureVisible(); if (m_state == null) { m_state = new PdfOutputState { PreviewPath = Utilities.GetTemporaryFileWithExactName("Preview.pdf") }; } m_state.IsModified = true; }
public static List<WorkbookItem> ResolveWorkbookItemsFromWorkbook(string filename) { Workbook workbook = new Workbook(); workbook.Open(filename); List<WorkbookItem> unresolvedWorkbookItems = workbook.GetWorkbookItems(); List<WorkbookItem> resolvedWorkbookItems = new List<WorkbookItem>(); if (unresolvedWorkbookItems.Count > 0) { DocumentProviderProxy docprov = new DocumentProviderProxy(); foreach (WorkbookItem item in unresolvedWorkbookItems) { try { tagWSDOCUMENT wsdoc = docprov.GetDocument(item.DocumentId); WorkbookItem newItem = new WorkbookItem(wsdoc) { PageSelection = item.PageSelection, PdfSecurityOptions = item.PdfSecurityOptions }; resolvedWorkbookItems.Add(newItem); } catch (System.Runtime.InteropServices.COMException e) { string error = docprov.GetErrorDescription(e.ErrorCode) ; error = string.IsNullOrEmpty(error) ? "Failed to resolve document in workbook: " + Environment.NewLine + "[" + e.Message + "]" : error; error += Environment.NewLine + Environment.NewLine + "Document: " + item.DocumentId; WsMessage.ShowMessage(IntPtr.Zero, error, MessageButtons.WsOK, MessageBranding.WsDefault, MessageType.WsErrorIcon, "", -1); } } } return resolvedWorkbookItems; }
// Return the pages to be delete public static int[] GetPageNumbersToDelete(WorkbookItem workbookItem) { if (workbookItem == null || workbookItem.PageSelection == null || String.IsNullOrEmpty(workbookItem.Pdf) || !File.Exists(workbookItem.Pdf)) { throw new ArgumentException("Invalid parameter"); } if (workbookItem.PageSelection.Type == PageSelectionType.All && String.IsNullOrEmpty(workbookItem.PageSelection.Range)) { return new int[0]; } // Page numbers will always be 1, 2, 3...n so effectively the HasSet is in a ascending order HashSet<int> pageNumbers = GetAllPageNumbers(Workshare.Pdf.Edit.PageCount(workbookItem.Pdf)); if (pageNumbers.Count == 0) { return new int[0]; } if (!String.IsNullOrEmpty(workbookItem.PageSelection.Range)) { HashSet<int> pagesToPrint = GetPageNumbersInRange(workbookItem.PageSelection.Range); pageNumbers.RemoveWhere(item => pagesToPrint.Contains(item)); return pageNumbers.ToArray(); } if (workbookItem.PageSelection.Type == PageSelectionType.Even) { // Remove even pages numbers, return odd page number. pageNumbers.RemoveWhere( item => item % 2 == 0 ); return pageNumbers.ToArray(); } if (workbookItem.PageSelection.Type == PageSelectionType.Odd) { // Remove odd pages numbers, return even page number. pageNumbers.RemoveWhere( item => item % 2 > 0); return pageNumbers.ToArray(); } return new int[0]; }
public abstract string PrintRange(WorkbookItem wi, PageSelection PageSelection);
public abstract string Print(WorkbookItem wi);
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; } }
private static void CopySecurityInformation(PdfSecurityOptions pdfSecurityOptions, WorkbookItem wi) { if (pdfSecurityOptions == null) return; if (wi.PdfSecurityOptions == null) { wi.PdfSecurityOptions = new PdfSecurityOptions(); } wi.PdfSecurityOptions.DisableComments = pdfSecurityOptions.DisableComments; wi.PdfSecurityOptions.DisableCopy = pdfSecurityOptions.DisableCopy; wi.PdfSecurityOptions.DisableModification = pdfSecurityOptions.DisableModification; wi.PdfSecurityOptions.DisablePrinting = pdfSecurityOptions.DisablePrinting; wi.PdfSecurityOptions.FullSecurity = pdfSecurityOptions.FullSecurity; wi.PdfSecurityOptions.Password = pdfSecurityOptions.Password; wi.PdfSecurityOptions.PassWordVerified = pdfSecurityOptions.PassWordVerified; }
public override string PrintRange(WorkbookItem wi, PageSelection range) { using (new WsActivationContext()) { string PageSelection = ""; int pageOption = 0; if (range != null) { PageSelection = range.Range; pageOption = (int)range.Type; } string destination = Workshare.Pdf.Combine.Coordinator.Utilities.GetTemporaryFileWithPdfExtension(); Publisher.PublishWithWord(wi.TempCopy, destination, HostApplication, PageSelection, pageOption); return destination; } }
private void CleanDocumentIfRequired(WorkbookItem workbookItem) { PdfSecurityOptions options = workbookItem.PdfSecurityOptions; if (options != null && options.CleanBeforePdf) { IBatchCleanController bcc = BatchCleanFactory.GetInstance(); bcc.AddFiles(new string[] { workbookItem.TempCopy }, false); bcc.SetCleaningOptions(SkipElementsThatWillBeLostDuringConversionToPdf(options.CleaningOptions)); bcc.Process(); } }
public override string PrintRange(WorkbookItem wi, PageSelection PageSelection) { throw new NotImplementedException("Printing page ranges not supported by Outlook object model"); }
public override string Print(WorkbookItem wi) { using (new WsActivationContext()) { string destination = Workshare.Pdf.Combine.Coordinator.Utilities.GetTemporaryFileWithPdfExtension(); MsoTriState state = MsoTriState.msoFalse; PowerPoint._Presentation presentation = null; bool foundOpenPresentation = false; if (wi.PdfSecurityOptions == null || !wi.PdfSecurityOptions.CleanBeforePdf) presentation = FindOpenPresentation(wi); if (presentation != null) foundOpenPresentation = true; else { presentation = (HostApplication as PowerPoint._Application).Presentations.Open(wi.TempCopy, state, state, state); } Publisher.PublishWithPowerPoint(destination, presentation); if (!foundOpenPresentation) { presentation.Close(); } return destination; } }