private void btnSaveImage_Click(object sender, EventArgs e) { if (!IsValid()) { return; } for (int i = 1; i <= numSignatures.Value; i++) { InkPicture inkPictureCtrl = this.Controls.Find(string.Concat(INC_CTRL_NAME, i), true).FirstOrDefault() as InkPicture; string fileToSaveJpeg = string.Empty; SignatureInfo item = documentEditProperties.SignatureInfoList.Where(x => x.Number == i).FirstOrDefault(); if (!imageSaverHelper.SaveSignatureToArray(inkPictureCtrl, ref item)) { break; } } PopulateNonDisplayed(); Globals.ThisAddIn.AddSignatures(); }
public bool SaveSignatureToArray(InkPicture inkPictureCtrl, ref SignatureInfo item) { try { string fileToSaveGif = string.Empty; if (inkPictureCtrl.Ink.Strokes.Count == 0) { return(true); } if (!Directory.Exists(FILE_NAME)) { MessageBox.Show(string.Format("Electronic Signatures were not transferred to the PDF file. {0}Please contact your system Administrator.", Environment.NewLine), "Error on saving document as PDF"); logger.Log(LogLevel.Error, string.Format("Directory {0} does not exist.", FILE_NAME)); return(false); } fileToSaveGif = Path.Combine(FILE_NAME, string.Concat(DateTime.Now.Ticks, ".Gif")); if (!string.IsNullOrEmpty(fileToSaveGif)) { if (File.Exists(fileToSaveGif)) { File.Delete(fileToSaveGif); } } byte[] bytes = (byte[])inkPictureCtrl.Ink.Save(PersistenceFormat.Gif, CompressionMode.NoCompression); item.PictureByteArray = bytes; item.PicturePath = fileToSaveGif; } catch (Exception ex) { MessageBox.Show(string.Format("Electronic Signatures were not transferred to the PDF file. {0}. Pleae contact system Administrator.", Environment.NewLine), "Saving documnet as PDF"); logger.LogException(LogLevel.Error, "SaveSignatureToArray", ex); return(false); } return(true); }
private static List <SignatureInfo> GetBodySignatureCtrls(Word.Document doc) { List <SignatureInfo> signaturesBody = new List <SignatureInfo>(); int counter = 1; try { foreach (Microsoft.Office.Interop.Word.ContentControl control in doc.ContentControls) { //MessageBox.Show("body:"+control.Tag); if (control.Tag.ToUpper().Contains(SIGNATURE_FIELD)) { //12/03/2017 - Do not allow typing in this field from inside the document //control.LockContents = false; //control.LockContentControl = false; //Tag will include section and name in the format: //B:Signature1 //F1:Signature2 //F2:Signature2 string[] parts = control.Tag.ToUpper().Split(':'); SignatureInfo signatureInfo = new SignatureInfo { Title = control.Title, Tag = parts.Length > 1 ? parts[1] : control.Tag, SignatureControl = control, SignatureControlPosition = parts.Length > 1 ? parts[0] : "Body" }; counter++; signaturesBody.Add(signatureInfo); } } } catch (Exception ex) { logger.LogException(LogLevel.Error, "GetBodySignatureCtrls", ex); } return(signaturesBody); }
private static List <SignatureInfo> GetHeaderSignatureCtrls(Word.Document doc) { List <SignatureInfo> signaturesHeader = new List <SignatureInfo>(); try { foreach (Microsoft.Office.Interop.Word.Section wordSection in doc.Sections) { foreach (Microsoft.Office.Interop.Word.HeaderFooter wordHeader in wordSection.Headers) { Microsoft.Office.Interop.Word.Range docRange = wordHeader.Range; ContentControls headerControls = docRange.ContentControls; if (headerControls != null) { int counter = 1; foreach (Microsoft.Office.Interop.Word.ContentControl control in headerControls) { //MessageBox.Show("headerControls:" + control.Tag); if (control.Tag.ToUpper().Contains(SIGNATURE_FIELD)) { //12/03/2017 - Do not allow typing in this field from inside the document //control.LockContents = false; //control.LockContentControl = false; //Tag will include section and name in the format: //B:Signature1 //F1:Signature2 //F2:Signature2 string[] parts = control.Tag.ToUpper().Split(':'); SignatureInfo signatureInfo = new SignatureInfo { Title = control.Title, Tag = parts.Length > 1 ? parts[1] : control.Tag, SignatureControl = control, SignatureControlPosition = parts.Length > 1 ? parts[0] : "Header" }; counter++; signaturesHeader.Add(signatureInfo); } } } if (Marshal.IsComObject(docRange)) { Marshal.ReleaseComObject(docRange); } if (Marshal.IsComObject(headerControls)) { Marshal.ReleaseComObject(headerControls); } if (Marshal.IsComObject(wordHeader)) { Marshal.ReleaseComObject(wordHeader); } } if (Marshal.IsComObject(wordSection)) { Marshal.ReleaseComObject(wordSection); } } } catch (Exception ex) { logger.LogException(LogLevel.Error, "GetHeaderSignatureCtrls", ex); } return(signaturesHeader); }
internal static void ByteArrayToImageFilebyMemoryStream(SignatureInfo signatureInfo) { ByteArrayToImageFilebyMemoryStream(signatureInfo.PictureByteArray, signatureInfo.PicturePath); }