Exemple #1
0
        /// <summary>
        /// Add word signature options
        /// </summary>
        /// <returns>SignOptions</returns>
        public override SignOptions SignWord()
        {
            ImageSignOptions signOptions = new ImageSignOptions(SignatureData.SignatureGuid);

            SetOptions(signOptions);
            return(signOptions);
        }
Exemple #2
0
        /// <summary>
        /// Sign document with image signature
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Basic Usage] # SignWithImage : Sign document with image\n");

            // The path to the documents directory.
            string filePath  = Constants.SAMPLE_PDF;
            string fileName  = Path.GetFileName(filePath);
            string imagePath = Constants.ImageHandwrite;

            string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithImage", fileName);

            using (Signature signature = new Signature(filePath))
            {
                ImageSignOptions options = new ImageSignOptions(imagePath)
                {
                    // set signature position
                    Left     = 50,
                    Top      = 50,
                    AllPages = true
                };

                // sign document to file
                SignResult result = signature.Sign(outputFilePath, options);

                Console.WriteLine($"\nSource document signed successfully with {result.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
            }
        }
Exemple #3
0
        static ImageSignOptions GetImageSignOptions()
        {
            string imagePath = Constants.ImageHandwrite;

            ImageSignOptions result = new ImageSignOptions(imagePath);

            // alignment settings
            result.Left       = 100;
            result.Top        = 350;
            result.Width      = 200;
            result.Height     = 120;
            result.AllPages   = true;
            result.PageNumber = 1;
            result.PagesSetup = new PagesSetup()
            {
                FirstPage = true, LastPage = false, OddPages = true, EvenPages = false, PageNumbers = { 1, 2, 3 }
            };
            result.HorizontalAlignment = Domain.HorizontalAlignment.Left;
            result.VerticalAlignment   = Domain.VerticalAlignment.Center;

            // border settings
            result.Border.Color        = System.Drawing.Color.Red;
            result.Border.DashStyle    = GroupDocs.Signature.Domain.DashStyle.DashLongDash;
            result.Border.Transparency = 0.8;
            result.Border.Weight       = 2;
            result.Border.Visible      = true;

            return(result);
        }
Exemple #4
0
 private static void SetOptions(ImageSignOptions signOptions)
 {
     signOptions.Left          = Convert.ToInt32(SignatureData.Left);
     signOptions.Top           = Convert.ToInt32(SignatureData.Top);
     signOptions.Width         = Convert.ToInt32(SignatureData.ImageWidth);
     signOptions.Height        = Convert.ToInt32(SignatureData.ImageHeight);
     signOptions.PageNumber    = SignatureData.PageNumber;
     signOptions.RotationAngle = SignatureData.Angle;
 }
Exemple #5
0
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Quick Start] # Options serialization and deserialization\n");

            List <SignOptions> collection = new List <SignOptions>();

            TextSignOptions textSignOptions = GetTextSignOptions();

            collection.Add(textSignOptions);

            ImageSignOptions imageSignOptions = GetImageSignOptions();

            collection.Add(imageSignOptions);

            DigitalSignOptions digitalSignOptions = GetDigitalSignOptions();

            collection.Add(digitalSignOptions);

            BarcodeSignOptions barcodeSignOptions = GetBarcodeSignOptions();

            collection.Add(barcodeSignOptions);

            QrCodeSignOptions qrCodeSignOptions = GetQrCodeSignOptions();

            collection.Add(qrCodeSignOptions);

            string serialized = JsonConvert.SerializeObject(collection);

            JsonConverter[] converters = { new SignOptionsJsonConverter(), new BarcodeTypeJsonConverter(), new QrCodeTypeJsonConverter() };

            List <SignOptions> deserialized = JsonConvert.DeserializeObject <List <SignOptions> >(serialized, converters);

            Console.WriteLine(deserialized.Count);

            if (deserialized != null)
            {
                // The path to the documents directory.
                string filePath = Constants.SAMPLE_PDF;
                string fileName = System.IO.Path.GetFileName(filePath);

                string outputFilePath = Path.Combine(Constants.OutputPath, "OptionsSerialization", fileName);

                using (Signature signature = new Signature(filePath))
                {
                    // sign document to file
                    SignResult signResult = signature.Sign(outputFilePath, deserialized);

                    Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
                }
            }
        }
        /// <summary>
        /// Sign document with text signature applying specific options
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # SignWithStretchMode : Sign document with text signature applying specific options\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_WORDPROCESSING;
            string fileName = Path.GetFileName(filePath);

            string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithStretch", fileName);

            using (Signature signature = new Signature(filePath))
            {
                // define several signature options of different types and settings
                TextSignOptions textOptions = new TextSignOptions("This is test message")
                {
                    AllPages          = true,
                    VerticalAlignment = VerticalAlignment.Top,
                    Margin            = new Padding(50),
                    Stretch           = StretchMode.PageWidth
                };
                BarcodeSignOptions barcodeOptions = new BarcodeSignOptions("123456")
                {
                    AllPages          = true,
                    EncodeType        = BarcodeTypes.Code128,
                    VerticalAlignment = VerticalAlignment.Bottom,
                    Margin            = new Padding(50),
                    Stretch           = StretchMode.PageWidth
                };
                ImageSignOptions imageOptions = new ImageSignOptions()
                {
                    AllPages            = true,
                    Stretch             = StretchMode.PageHeight,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    ImageFilePath       = Constants.ImageHandwrite
                };

                // define list of signature options
                List <SignOptions> listOptions = new List <SignOptions>();

                listOptions.Add(textOptions);
                listOptions.Add(barcodeOptions);
                listOptions.Add(imageOptions);

                // sign document to file
                SignResult signResult = signature.Sign(outputFilePath, listOptions);
                Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
            }
        }
Exemple #7
0
        /// <summary>
        /// Sign document with image signature applying specific options
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # SignWithImageAppearance : Sign document with image signature applying specific options\n");

            // The path to the documents directory.
            string filePath  = Constants.SAMPLE_WORDPROCESSING;
            string fileName  = Path.GetFileName(filePath);
            string imagePath = Constants.ImageHandwrite;

            string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithAppearances", "DocxImageAppearance.docx");

            using (Signature signature = new Signature(filePath))
            {
                ImageSignOptions options = new ImageSignOptions(imagePath)
                {
                    // set signature position
                    Left = 50,
                    Top  = 200,
                    // set signature rectangle
                    Width  = 100,
                    Height = 30,
                    Margin = new Padding()
                    {
                        Bottom = 20, Right = 20
                    },
                    Border = new Border()
                    {
                        Color        = Color.DarkGreen,
                        DashStyle    = DashStyle.DashLongDashDot,
                        Transparency = 0.5,
                        Visible      = true,
                        Weight       = 2
                    },
                    // setup image additional appearance as Brightness and Border
                    Appearance = new ImageAppearance()
                    {
                        Grayscale       = true,
                        Contrast        = 0.2f,
                        GammaCorrection = 0.3f,
                        Brightness      = 0.9f,
                    }
                };

                // sign document to file
                SignResult signResult = signature.Sign(outputFilePath, options);
                Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
            }
        }
        private ImageSignOptions GetImageSignOptions(string signImagePath, string signLocation, string signSize)
        {
            var options = new ImageSignOptions(signImagePath)
            {
                Width               = 100,
                Height              = 100,
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,

                Margin = new Padding(10)
            };

            TextShadow shadow = new TextShadow()
            {
                Color        = Color.DarkGray,
                Angle        = 65,
                Blur         = 3,
                Distance     = 4,
                Transparency = 0.3
            };

            options.Extensions.Add(shadow);

            QrCodeSignOptions locationOptions = GetLocationOptions(signLocation);

            options.HorizontalAlignment = locationOptions.HorizontalAlignment;
            options.VerticalAlignment   = locationOptions.VerticalAlignment;

            switch (signSize)
            {
            case "small":
                options.Width  = 50;
                options.Height = 50;
                break;

            case "medium":
                options.Width  = 50 * 2;
                options.Height = 50 * 2;
                break;

            case "large":
                options.Width  = 50 * 3;
                options.Height = 50 * 3;
                break;
            }

            return(options);
        }
Exemple #9
0
            protected override SignOptions Create(Type objectType, JObject jObject)
            {
                SignOptions result        = null;
                var         signatureType = GetSignatureType(jObject);

                // check SignatureType
                // check for Barcode options
                if (signatureType == SignatureType.Barcode)
                {
                    result = new BarcodeSignOptions();
                }
                // check for QrCode options
                if (result == null && signatureType == SignatureType.QrCode)
                {
                    result = new QrCodeSignOptions();
                }
                // check for digital options
                if (result == null && signatureType == SignatureType.Digital)
                {
                    result = new DigitalSignOptions();
                }
                // check for text options
                if (result == null && signatureType == SignatureType.Text)
                {
                    result = new TextSignOptions();
                }
                // check for image options
                if (result == null && signatureType == SignatureType.Image)
                {
                    result = new ImageSignOptions();
                }
                // check for stamp options
                if (result == null && signatureType == SignatureType.Stamp)
                {
                    result = new StampSignOptions();
                }

                return(result);
            }
        /// <summary>
        /// Sign document with image signature applying specific options
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # SignWithImageAdvanced : Sign document with image signature applying specific options\n");

            // The path to the documents directory.
            string filePath  = Constants.SAMPLE_PDF;
            string fileName  = Path.GetFileName(filePath);
            string imagePath = Constants.ImageHandwrite;

            string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithImageAdvanced", fileName);

            using (Signature signature = new Signature(filePath))
            {
                ImageSignOptions options = new ImageSignOptions(imagePath)
                {
                    // set signature position
                    Left = 100,
                    Top  = 100,

                    // set signature rectangle
                    Width  = 200,
                    Height = 100,

                    // set signature alignment
                    // when VerticalAlignment is set the Top coordinate will be ignored.
                    // Use Margin properties Top, Bottom to provide vertical offset
                    VerticalAlignment = VerticalAlignment.Top,

                    // when HorizontalAlignment is set the Left coordinate will be ignored.
                    // Use Margin properties Left, Right to provide horizontal offset
                    HorizontalAlignment = HorizontalAlignment.Center,

                    Margin = new Padding()
                    {
                        Top = 120, Right = 120
                    },

                    // set rotation
                    RotationAngle = 45,

                    // setup signature border
                    Border = new Border()
                    {
                        Visible   = true,
                        Color     = Color.OrangeRed,
                        DashStyle = DashStyle.DashDotDot,
                        Weight    = 5
                    }
                };

                // sign document to file
                SignResult signResult = signature.Sign(outputFilePath, options);
                Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");

                Console.WriteLine("\nList of newly created signatures:");
                int number = 1;
                foreach (BaseSignature temp in signResult.Succeeded)
                {
                    Console.WriteLine($"Signature #{number++}: Type: {temp.SignatureType} Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
            }
        }
        /// <summary>
        /// Following example shows how to process Image Signature over all signature life-cycle.
        /// First document is being signed with Image Signature, then verified for it, searched for same, updating and finally deleting this signature.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # ProcessingImageSignatureOverCRUD : Process Image Signature over all signature life-cycle\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_WORDPROCESSING;
            string fileName = Path.GetFileName(filePath);

            string        outputFilePath = Path.Combine(Constants.OutputPath, "ProcessingImageSignatureOverCRUD", fileName);
            List <string> signatureIds   = new List <string>();

            // -----------------------------------------------------------------------------------------------------------------------------
            // STEP 1. Sign document with Image Signature
            // -----------------------------------------------------------------------------------------------------------------------------
            using (Signature signature = new Signature(filePath))
            {
                ImageSignOptions signOptions = new ImageSignOptions(Constants.ImageStamp)
                {
                    VerticalAlignment   = VerticalAlignment.Top,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Width  = 100,
                    Height = 40,
                    Margin = new Padding(20)
                };
                // sign document to file
                SignResult signResult = signature.Sign(outputFilePath, signOptions);
                Console.WriteLine("\nDocument {filePath} was signed with following signatures:");
                foreach (BaseSignature temp in signResult.Succeeded)
                {
                    // collect newly created signature' Id
                    signatureIds.Add(temp.SignatureId);
                    Console.WriteLine($"Signature : {temp.SignatureType} Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
            }
            // -----------------------------------------------------------------------------------------------------------------------------
            // STEP 2. Search document for Image Signature
            // -----------------------------------------------------------------------------------------------------------------------------
            using (Signature signature = new Signature(outputFilePath))
            {
                ImageSearchOptions searchOptions = new ImageSearchOptions()
                {
                    // specify special pages to search on
                    AllPages = true
                };
                // search for image signatures in document
                List <ImageSignature> signatures = signature.Search <ImageSignature>(searchOptions);
                Console.WriteLine("\nSource document contains following Image signature(s).");
                // enumerate all signature for output
                foreach (ImageSignature imageSignature in signatures)
                {
                    if (imageSignature != null)
                    {
                        Console.WriteLine($"Found Image signature at page {imageSignature.PageNumber} and Image Size '{imageSignature.Size}'.");
                        Console.WriteLine($"Location at {imageSignature.Left}-{imageSignature.Top}. Size is {imageSignature.Width}x{imageSignature.Height}.");
                    }
                }
                // -----------------------------------------------------------------------------------------------------------------------------
                // STEP 3. Update document Image Signature after searching it
                // -----------------------------------------------------------------------------------------------------------------------------
                foreach (ImageSignature imageSignature in signatures)
                {
                    // change position
                    imageSignature.Left = imageSignature.Left + 100;
                    imageSignature.Top  = imageSignature.Top + 100;
                    // change size. Please note not all documents support changing signature size
                    imageSignature.Width  = 200;
                    imageSignature.Height = 50;
                }
                List <BaseSignature> signaturesToUpdate = signatures.ConvertAll(p => (BaseSignature)p);
                UpdateResult         updateResult;
                updateResult = signature.Update(signaturesToUpdate);
                if (updateResult.Succeeded.Count == signatures.Count)
                {
                    Console.WriteLine("\nAll signatures were successfully updated!");
                }
                else
                {
                    Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}");
                    Helper.WriteError($"Not updated signatures : {updateResult.Failed.Count}");
                }
                Console.WriteLine("List of updated signatures:");
                foreach (BaseSignature temp in updateResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
                // -----------------------------------------------------------------------------------------------------------------------------
                // STEP 4. Update document Image Signature on saved SignatureId
                // create list of Image Signature by known SignatureId
                // -----------------------------------------------------------------------------------------------------------------------------
                signaturesToUpdate.Clear();
                foreach (var item in signatureIds)
                {
                    ImageSignature temp = new ImageSignature(item)
                    {
                        Width  = 150,
                        Height = 30,
                        Left   = 100,
                        Top    = 100
                    };
                    signaturesToUpdate.Add(temp);
                }
                // update all found signatures
                updateResult = signature.Update(signaturesToUpdate);
                if (updateResult.Succeeded.Count == signatures.Count)
                {
                    Console.WriteLine("\nAll signatures were successfully updated!");
                }
                else
                {
                    Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}");
                    Helper.WriteError($"Not updated signatures : {updateResult.Failed.Count}");
                }
                Console.WriteLine("List of updated signatures:");
                foreach (BaseSignature temp in updateResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
                // -----------------------------------------------------------------------------------------------------------------------------
                // STEP 5. Delete document Image Signature by id
                // create list of Image Signature by known SignatureId
                signaturesToUpdate.Clear();
                foreach (var item in signatureIds)
                {
                    ImageSignature temp = new ImageSignature(item);
                    signaturesToUpdate.Add(temp);
                }
                // delete all signatures
                DeleteResult deleteResult = signature.Delete(signaturesToUpdate);
                if (deleteResult.Succeeded.Count == signaturesToUpdate.Count)
                {
                    Console.WriteLine("\nAll signatures were successfully deleted!");
                }
                else
                {
                    Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}");
                    Helper.WriteError($"Not deleted signatures : {deleteResult.Failed.Count}");
                }
                Console.WriteLine("List of deleted signatures:");
                foreach (BaseSignature temp in deleteResult.Succeeded)
                {
                    Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
                }
            }
        }
        /// <summary>
        /// Sign document with multiple signature types
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Basic Usage] # SignWithMultipleOptions : Sign document with multiple signature types \n");

            // The path to the documents directory.
            string filePath       = Constants.SAMPLE_WORDPROCESSING;
            string outputFilePath = Path.Combine(Constants.OutputPath, "SignWithMultiple", "SignWithMultiple.docx");

            using (Signature signature = new Signature(filePath))
            {
                // define several signature options of different types and settings
                TextSignOptions textOptions = new TextSignOptions("Text signature")
                {
                    VerticalAlignment   = VerticalAlignment.Top,
                    HorizontalAlignment = HorizontalAlignment.Left
                };
                BarcodeSignOptions barcodeOptions = new BarcodeSignOptions("123456")
                {
                    EncodeType = BarcodeTypes.Code128,
                    Left       = 0,
                    Top        = 150,
                    Height     = 50,
                    Width      = 200
                };
                QrCodeSignOptions qrcodeOptions = new QrCodeSignOptions("JohnSmith")
                {
                    EncodeType = QrCodeTypes.QR,
                    Left       = 0,
                    Top        = 220
                };
                DigitalSignOptions digitalOptions = new DigitalSignOptions(Constants.CertificatePfx)
                {
                    ImageFilePath = Constants.ImageHandwrite,
                    Left          = 20,
                    Top           = 400,
                    Height        = 100,
                    Width         = 100,
                    Password      = "******"
                };
                ImageSignOptions imageOptions = new ImageSignOptions(Constants.ImageStamp)
                {
                    Left   = 20,
                    Top    = 550,
                    Height = 100,
                    Width  = 100
                };
                MetadataSignOptions metaOptions = new MetadataSignOptions();
                WordProcessingMetadataSignature[] metaSignatures = new WordProcessingMetadataSignature[]
                {
                    new WordProcessingMetadataSignature("Author", "Mr.Scherlock Holmes"),
                    new WordProcessingMetadataSignature("CreatedOn", DateTime.Now)
                };
                metaOptions.Signatures.AddRange(metaSignatures);

                // define list of signature options
                List <SignOptions> listOptions = new List <SignOptions>();

                listOptions.Add(textOptions);
                listOptions.Add(barcodeOptions);
                listOptions.Add(qrcodeOptions);
                listOptions.Add(digitalOptions);
                listOptions.Add(imageOptions);
                listOptions.Add(metaOptions);

                // sign document to file
                SignResult result = signature.Sign(outputFilePath, listOptions);

                Console.WriteLine($"\nSource document signed successfully with {result.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
            }
        }