Although I can add a signature line to the word document, I don't feel confident in my strategy. I looked everywhere for solutions to my situation but came up empty-handed.
private void CreateNewPage()
{
object missing = System.Reflection.Missing.Value;
object fileName = @"C:\docs\mydoc.docx";
object readOnly = false;
object isVisible = true;
//Start Word and open a document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref isVisible, ref missing,
ref missing, ref missing, ref missing);
// var numberOfPages = oDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, false);
object oEndOfDoc = "\\endofdoc";
object paramNextPage = Word.WdBreakType.wdSectionBreakNextPage;
oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertBreak(ref paramNextPage);
//Insert a page break
object breakPage = Word.WdBreakType.wdPageBreak;
object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
object originalFormat = Word.WdOriginalFormat.wdOriginalDocumentFormat;
object routeDocument = false;
object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
object which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToLast;
object count = 3;
oWord.Selection.GoTo(ref what, ref which, ref count, ref missing);
object sigID = "{00000000-0000-0000-0000-000000000000}";
Timer t = new Timer();
t.Elapsed += (sender, args) =>
{
SendKeys.SendWait("{TAB}");
SendKeys.SendWait("~");
t.Stop();
};
t.Interval = 2000;
t.Start();
try
{
oWord.Activate();
SignatureSet signatureSet = oWord.ActiveDocument.Signatures;
// signatureSet.ShowSignaturesPane = false;
Signature objSignature = signatureSet.AddSignatureLine(sigID);
objSignature.Setup.SuggestedSigner = "docSigner";
objSignature.Setup.SuggestedSignerEmail = "abc@xyz.com";
objSignature.Setup.ShowSignDate = true;
// dynamic shape = objSignature.SignatureLineShape;
}
catch (Exception ex){}
oWord.Documents.Save();
oWord.Quit();
try
{
Marshal.ReleaseComObject(oWord);
}
catch (Exception){}
}
Well as you see below, when I call AddSignatureLine funciton, this window opens modal (like showdialog) and until close this, the code does not flow.
I bypassed this by using send key but we know that it is not a good way. However, If I can't find any other solution then I will try to do that by finding this window (word's child window) using Win32 APIs.
But I am curious if is there any way to bypass this. Because there are a thousand documents and I am looking for also a faster way.