private void MonitorDocument(Word.Document Doc) { // Monitor doc if (!documentEditProperties.ContainsKey(Doc.Name)) { bool isSAPOL = DocContent.IsSAPOL(Doc); documentEditProperties.Add(Doc.Name, new TemplateDetails(isSAPOL)); //Globals.Ribbons.SignatureRibbon.SetToggleSignatureLock(isSAPOL); } }
//10/05/2017 private void LockSignatures(Word.Document doc) { List <Microsoft.Office.Interop.Word.ContentControl> signatures = DocContent.GetAllContentControls(doc); foreach (Microsoft.Office.Interop.Word.ContentControl item in signatures) { item.LockContentControl = true; item.LockContents = true; } }
private void SaveAsPDF() { try { Word.Document doc = this.Application.ActiveDocument; DocContent.UpdateDateModifiedCtrls(doc); DocContent.SaveDocumentAsPDF(doc, documentEditProperties[doc.Name].PDFFullName); } catch (System.IO.IOException ex) { MessageBox.Show(string.Format("The following error occurs while saving the document into PDF format: {0}", ex.Message), "Error on saving as PDF"); } catch (Exception ex) { logger.LogException(LogLevel.Error, "SaveAsPDF", ex); } }
private void SaveAsWordDocumentWithoutSignatures() { try { Word.Document doc = this.Application.ActiveDocument; string oldName = doc.Name; DocContent.SaveDocumentAsWordWithoutSignatures(doc, documentEditProperties[doc.Name].PDFFullName); ResetDocumentInDictionary(doc, oldName); } catch (System.IO.IOException ex) { MessageBox.Show(string.Format("The following error occurs while saving the document into word document format: {0}", ex.Message), "Error on saving as Word Document Without the Signatures"); } catch (Exception ex) { logger.LogException(LogLevel.Error, "SaveAsWordDocumentWithoutSignatures", ex); } }
private void eventInterface_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel) { try { //this is done as a substitution for AfterSave event! Cancel = true; SaveAsUI = false; string oldName = Doc.Name; Doc.Saved = false; DocContent.UpdateDateModifiedCtrls(Doc); Doc.Save(); ResetDocumentInDictionary(Doc, oldName); } catch (Exception e) { logger.LogException(LogLevel.Error, "eventInterface_DocumentBeforeSave", e); } }
private void eventInterface_DocumentBeforeClose(Word.Document Doc, ref bool Cancel) { try { //if (Doc.Name.ToUpper().Contains(TEMPLATE_EXT)) // return; if (!Doc.Name.ToUpper().Contains(TEMPLATE_EXT) && documentEditProperties.ContainsKey(Doc.Name) && documentEditProperties[Doc.Name].IsSAPOL) { DocContent.UpdateDateModifiedCtrls(Doc); } if (documentEditProperties.ContainsKey(Doc.Name)) { ReleaseSignatureInfo(documentEditProperties[Doc.Name]); } // Remove task pane RemoveTaskPaneFromWindow(Doc.ActiveWindow); } catch (Exception e) { logger.LogException(LogLevel.Error, "eventInterface_DocumentBeforeClose", e); } }
internal void AddSignatures() { TemplateDetails details = documentEditProperties[this.Application.ActiveDocument.Name]; Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument; //Save document using SaveAs function SaveAsWordDocumentWithoutSignatures(); //12/03/2017 - unlock controls to insert signatures DocContent.UnlockHeaderSignatures(doc); DocContent.UnlockBodySignatures(doc); DocContent.UnlockFooterSignatures(doc); int selectionStart = 0; //Add Signatures to document foreach (SignatureInfo item in details.SignatureInfoList) { try { DocContent.ByteArrayToImageFilebyMemoryStream(item); if (!string.IsNullOrEmpty(item.PicturePath)) { DocContent.AddPictureToControl(doc, item.SignatureControl, item.PicturePath, ref selectionStart); if (File.Exists(item.PicturePath)) { File.Delete(item.PicturePath); } } } catch (Exception ex) { logger.LogException(LogLevel.Error, "AddSignatures1", ex); } } //Save as pdf SaveAsPDF(); try { ////09/05/2017 ////Remove pictures //foreach (SignatureInfo item in details.SignatureInfoList) //{ //// 09/05/2017 - ira // item.SignatureControl.Delete(); // DocContent.DeletePictureFromControl(doc, item.SignatureControl); //} ////logger.Log(LogLevel.Warn, "B4 SaveAsWordDocumentWithoutSignatures"); ////Save as Word Document without the signature //SaveAsWordDocumentWithoutSignatures(); ////logger.Log(LogLevel.Warn, "After SaveAsWordDocumentWithoutSignatures"); RemoveTaskPaneFromWindow(); } catch (Exception ex) { logger.LogException(LogLevel.Error, "AddSignatures2", ex); } object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges; object originalFormat = Word.WdOriginalFormat.wdOriginalDocumentFormat; object routeDocument = false; doc.Close(ref saveOption, ref originalFormat, ref routeDocument); }
private void PopulateSignatureFileds() { Word.Document doc = this.Application.ActiveDocument; documentEditProperties[this.Application.ActiveDocument.Name].SignatureInfoList = DocContent.BuildSignatureList(doc); }