/// <summary>
        /// Signs the document obtained at the source location and saves it to the specified destination.
        /// </summary>
        private static void SignDocument(string srcDocumentPath, string dstDocumentPath,
                                         SignPersonTestClass signPersonInfo, string certificatePath, string certificatePassword)
        {
            // Create new document instance based on a test file that we need to sign.
            Document        document = new Document(srcDocumentPath);
            DocumentBuilder builder  = new DocumentBuilder(document);

            // Add info about responsible person who sign a document.
            SignatureLineOptions signatureLineOptions =
                new SignatureLineOptions {
                Signer = signPersonInfo.Name, SignerTitle = signPersonInfo.Position
            };

            // Add signature line for responsible person who sign a document.
            SignatureLine signatureLine = builder.InsertSignatureLine(signatureLineOptions).SignatureLine;

            signatureLine.Id = signPersonInfo.PersonId;

            // Save a document with line signatures into temporary file for future signing.
            builder.Document.Save(dstDocumentPath);

            // Create holder of certificate instance based on your personal certificate.
            // This is the test certificate generated for this example.
            CertificateHolder certificateHolder = CertificateHolder.Create(certificatePath, certificatePassword);

            // Link our signature line with personal signature.
            SignOptions signOptions = new SignOptions
            {
                SignatureLineId    = signPersonInfo.PersonId,
                SignatureLineImage = signPersonInfo.Image
            };

            // Sign a document which contains signature line with personal certificate.
            DigitalSignatureUtil.Sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
        }
        /// <summary>
        /// Creates a copy of a source document signed using provided signee information and X509 certificate.
        /// </summary>
        private static void SignDocument(string srcDocumentPath, string dstDocumentPath,
                                         Signee signeeInfo, string certificatePath, string certificatePassword)
        {
            Document        document = new Document(srcDocumentPath);
            DocumentBuilder builder  = new DocumentBuilder(document);

            // Configure and insert a signature line, an object in the document that will display a signature that we sign it with.
            SignatureLineOptions signatureLineOptions = new SignatureLineOptions
            {
                Signer      = signeeInfo.Name,
                SignerTitle = signeeInfo.Position
            };

            SignatureLine signatureLine = builder.InsertSignatureLine(signatureLineOptions).SignatureLine;

            signatureLine.Id = signeeInfo.PersonId;

            // First, we will save an unsigned version of our document.
            builder.Document.Save(dstDocumentPath);

            CertificateHolder certificateHolder = CertificateHolder.Create(certificatePath, certificatePassword);

            SignOptions signOptions = new SignOptions
            {
                SignatureLineId    = signeeInfo.PersonId,
                SignatureLineImage = signeeInfo.Image
            };

            // Overwrite the unsigned document we saved above with a version signed using the certificate.
            DigitalSignatureUtil.Sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
        }
        public void CreateNewSignatureLineAndSetProviderId()
        {
            //ExStart:CreateNewSignatureLineAndSetProviderID
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            SignatureLineOptions signatureLineOptions = new SignatureLineOptions
            {
                Signer              = "vderyushev",
                SignerTitle         = "QA",
                Email               = "*****@*****.**",
                ShowDate            = true,
                DefaultInstructions = false,
                Instructions        = "Please sign here.",
                AllowComments       = true
            };

            SignatureLine signatureLine = builder.InsertSignatureLine(signatureLineOptions).SignatureLine;

            signatureLine.ProviderId = Guid.Parse("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2");

            doc.Save(ArtifactsDir + "SignDocuments.SignatureLineProviderId.docx");

            SignOptions signOptions = new SignOptions
            {
                SignatureLineId = signatureLine.Id,
                ProviderId      = signatureLine.ProviderId,
                Comments        = "Document was signed by vderyushev",
                SignTime        = DateTime.Now
            };

            CertificateHolder certHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw");

            DigitalSignatureUtil.Sign(ArtifactsDir + "SignDocuments.SignatureLineProviderId.docx",
                                      ArtifactsDir + "SignDocuments.CreateNewSignatureLineAndSetProviderId.docx", certHolder, signOptions);
            //ExEnd:CreateNewSignatureLineAndSetProviderID
        }
        public void InsertSignatureLineCurrentPozition()
        {
            //ExStart
            //ExFor:SignatureLine
            //ExFor:SignatureLineOptions
            //ExFor:DocumentBuilder.InsertSignatureLine(SignatureLineOptions)
            //ExFor:DocumentBuilder.InsertSignatureLine(SignatureLineOptions)
            //ExSummary:Shows how to insert signature line and get signature line properties
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            SignatureLineOptions options = new SignatureLineOptions();
            options.Signer = "John Doe";
            options.SignerTitle = "Manager";
            options.Email = "*****@*****.**";
            options.ShowDate = true;
            options.DefaultInstructions = false;
            options.Instructions = "You need more info about signature line";
            options.AllowComments = true;

            builder.InsertSignatureLine(options);
            builder.InsertSignatureLine(options, RelativeHorizontalPosition.RightMargin, 2.0, RelativeVerticalPosition.Page, 3.0, WrapType.Inline);
            
            MemoryStream dstStream = new MemoryStream();
            doc.Save(dstStream, SaveFormat.Docx);

            Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
            SignatureLine signatureLine = shape.SignatureLine;

            Assert.AreEqual("John Doe", signatureLine.Signer);
            Assert.AreEqual("Manager", signatureLine.SignerTitle);
            Assert.AreEqual("*****@*****.**", signatureLine.Email);
            Assert.AreEqual(true, signatureLine.ShowDate);
            Assert.AreEqual(false, signatureLine.DefaultInstructions);
            Assert.AreEqual("You need more info about signature line", signatureLine.Instructions);
            Assert.AreEqual(true, signatureLine.AllowComments);
            Assert.AreEqual(false, signatureLine.IsSigned);
            Assert.AreEqual(false, signatureLine.IsValid);
            //ExEnd

            shape = (Shape)doc.GetChild(NodeType.Shape, 1, true);
            Assert.AreEqual(RelativeHorizontalPosition.RightMargin, shape.RelativeHorizontalPosition);
            Assert.AreEqual(2.0, shape.Left);
            Assert.AreEqual(RelativeVerticalPosition.Page, shape.RelativeVerticalPosition);
            Assert.AreEqual(3.0, shape.Top);
            Assert.AreEqual(WrapType.Inline, shape.WrapType);
            //Bug: If wraptype are not inline shape break his position (builder.InsertSignatureLine(options, RelativeHorizontalPosition.RightMargin, 2.0, RelativeVerticalPosition.Page, 3.0, WrapType.Inline);)
        }