Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void CreateNewPage()
  {
      object missing = System.Reflection.Missing.Value;
      object fileName = @"F:\Doc\test.docx";
      object readOnly = false;
      object isVisible = true;

      //Start Word and open a document.
      Microsoft.Office.Interop.Word._Application oWord;
      Microsoft.Office.Interop.Word._Document oDoc;
      oWord = new Microsoft.Office.Interop.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 = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage;

      oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertBreak(ref paramNextPage);
      //Insert a page break
      object breakPage = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;


      object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
      object originalFormat = Microsoft.Office.Interop.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}";


      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;
 objSignature.attachcertificate();
 objSignature.sign();
          //  dynamic shape = objSignature.SignatureLineShape;
      }
      catch (Exception ex) { MessageBox.Show(ex.Message); }

      oWord.Documents.Save();
      oWord.Quit();

      try
      {
          Marshal.ReleaseComObject(oWord);
      }
      catch (Exception e) { MessageBox.Show(e.Message); }
  }


What I have tried:

here im attaching my own certificate when trying to open that it will show some setup popup instead i need to automatically get sign
objSignature.attachcertificate();
 objSignature.sign();
Posted
Updated 16-Feb-21 21:36pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900