/// <summary>
        /// Add pdf signature data
        /// </summary>
        /// <returns>SignOptions</returns>
        public override SignOptions SignPdf()
        {
            // setup options
            StampSignOptions pdfSignOptions = new StampSignOptions();

            pdfSignOptions.Height                  = Convert.ToInt32(SignatureData.ImageHeight - 20);
            pdfSignOptions.Width                   = Convert.ToInt32(SignatureData.ImageWidth - 20);
            pdfSignOptions.Top                     = Convert.ToInt32(SignatureData.Top);
            pdfSignOptions.Left                    = Convert.ToInt32(SignatureData.Left);
            pdfSignOptions.PageNumber              = SignatureData.PageNumber;
            pdfSignOptions.RotationAngle           = SignatureData.Angle;
            pdfSignOptions.Background.Color        = getColor(stampData[stampData.Length - 1].backgroundColor);
            pdfSignOptions.BackgroundColorCropType = StampBackgroundCropType.OuterArea;
            // draw stamp lines
            for (int n = 0; n < stampData.Length; n++)
            {
                string text = "";
                // prepare line text
                for (int m = 0; m < stampData[n].textRepeat; m++)
                {
                    text = text + stampData[n].text;
                }
                // set reduction size - required to recalculate each stamp line height and font size after stamp resizing in the UI
                int reductionSize = CalculateRedactionSize(stampData[n]);

                // draw most inner line - horizontal text
                if ((n + 1) == stampData.Length)
                {
                    StampLine squareLine = PrepareHarisontalLine(stampData[n], text, reductionSize);
                    pdfSignOptions.InnerLines.Add(squareLine);
                    // check if stamp contains only one line
                    if (stampData.Length == 1)
                    {
                        // if stamp contains only one line draw it as outer and inner line
                        StampLine line = DrawOuterLineForSquare(stampData[n]);
                        pdfSignOptions.OuterLines.Add(line);
                    }
                }
                else
                {
                    // draw outer stamp lines - rounded
                    double    height = (stampData[n].radius - stampData[n + 1].radius) / reductionSize;
                    StampLine line   = DrawOuterCircle(stampData[n], stampData[n + 1].strokeColor, text, Convert.ToInt32(height), reductionSize);
                    pdfSignOptions.OuterLines.Add(line);
                }
            }
            return(pdfSignOptions);
        }
Пример #2
0
        /// <summary>
        /// Sign document with stamp signature
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Basic Usage] # SignWithStamp : Sign document with stamp\n");

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

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

            using (Signature signature = new Signature(filePath))
            {
                StampSignOptions options = new StampSignOptions()
                {
                    // set stamp signature position
                    Left   = 50,
                    Top    = 150,
                    Width  = 200,
                    Height = 200
                };

                // setup first external line of Stamp
                StampLine outerLine = new StampLine();
                outerLine.Text             = " * European Union ";
                outerLine.TextRepeatType   = StampTextRepeatType.FullTextRepeat;
                outerLine.Font.Size        = 12;
                outerLine.Height           = 22;
                outerLine.TextBottomIntent = 6;
                outerLine.TextColor        = Color.WhiteSmoke;
                outerLine.BackgroundColor  = Color.DarkSlateBlue;
                options.OuterLines.Add(outerLine);

                //Inner square lines - horizontal lines inside the rings
                StampLine innerLine = new StampLine();
                innerLine.Text      = "John Smith";
                innerLine.TextColor = Color.MediumVioletRed;
                innerLine.Font.Size = 20;
                innerLine.Font.Bold = true;
                innerLine.Height    = 40;
                options.InnerLines.Add(innerLine);

                // 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}.");
            }
        }
Пример #3
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);
            }
Пример #4
0
        /// <summary>
        /// Sign document with Stamp signature applying specific options
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # SignWithStampAdvanced : Sign document with Stamp signature applying specific options\n");

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

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

            using (Signature signature = new Signature(filePath))
            {
                // setup options with text of signature
                StampSignOptions signOptions = new StampSignOptions()
                {
                    Height = 300,
                    Width  = 300,

                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Margin = new Padding()
                    {
                        Right = 10, Bottom = 10
                    },
                    Transparency = 0.2,
                    Background   = new Background()
                    {
                        Color = Color.DarkOrange, Transparency = 0.5
                    },
                    Border = new Border()
                    {
                        Visible   = true, Color = Color.OrangeRed,
                        DashStyle = DashStyle.DashLongDashDot, Weight = 2
                    },
                    BackgroundColorCropType = StampBackgroundCropType.OuterArea,
                    ImageFilePath           = Constants.ImageHandwrite,
                    BackgroundImageCropType = StampBackgroundCropType.InnerArea,
                    AllPages = true
                };

                //add few outer round lines
                signOptions.OuterLines.Add(
                    new StampLine()
                {
                    Text           = "* European Union *",
                    TextRepeatType = StampTextRepeatType.FullTextRepeat,
                    Font           = new SignatureFont()
                    {
                        Size = 12, FamilyName = "Arial"
                    },
                    Height           = 22,
                    TextBottomIntent = 6,
                    TextColor        = Color.WhiteSmoke,
                    BackgroundColor  = Color.DarkSlateBlue
                }
                    );

                signOptions.OuterLines.Add(
                    new StampLine()
                {
                    Height          = 2,
                    BackgroundColor = Color.White
                }
                    );

                signOptions.OuterLines.Add(
                    new StampLine()
                {
                    Text           = "* Entrepreneur *",
                    TextRepeatType = StampTextRepeatType.FullTextRepeat,
                    TextColor      = Color.DarkSlateBlue,
                    Font           = new SignatureFont()
                    {
                        Size = 15
                    },
                    Height           = 30,
                    TextBottomIntent = 8,
                    InnerBorder      = new Border()
                    {
                        Color = Color.DarkSlateBlue, DashStyle = DashStyle.Dot
                    },
                    OuterBorder = new Border()
                    {
                        Color = Color.DarkSlateBlue
                    },
                }
                    );


                //Inner square lines
                signOptions.InnerLines.Add(
                    new StampLine()
                {
                    Text      = "John",
                    TextColor = Color.MediumVioletRed,
                    Font      = new SignatureFont()
                    {
                        Size = 20, Bold = true
                    },
                    Height = 40,
                }
                    );

                signOptions.InnerLines.Add(
                    new StampLine()
                {
                    Text      = "Smith",
                    TextColor = Color.MediumVioletRed,
                    Font      = new SignatureFont()
                    {
                        Size = 20, Bold = true
                    },
                    Height = 40
                }
                    );

                signOptions.InnerLines.Add(
                    new StampLine()
                {
                    Text      = "SSN 1230242424",
                    TextColor = Color.MediumVioletRed,
                    Font      = new SignatureFont()
                    {
                        Size = 12, Bold = true
                    },
                    Height = 40,
                }
                    );

                // sign document
                SignResult signResult = signature.Sign(outputFilePath, signOptions);
                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}");
                }
            }
        }
        private StampSignOptions GetStampSignOptions(string signText, string signLocation, string signSize)
        {
            StampSignOptions signOptions = new StampSignOptions()
            {
                Height = 250,
                Width  = 250,

                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin = new Padding()
                {
                    Right = 10, Bottom = 10
                },
                Background = new Background()
                {
                    Transparency = 0.2,
                    Brush        = new LinearGradientBrush(Color.Orange, Color.DarkOrange, 270)
                },
                BackgroundColorCropType = StampBackgroundCropType.OuterArea,
                //ImageFilePath = "example.jpg",
                BackgroundImageCropType = StampBackgroundCropType.InnerArea,
                AllPages = true
            };

            signOptions.OuterLines.Add(
                new StampLine()
            {
                Text           = $"*{signText}*",
                TextRepeatType = StampTextRepeatType.FullTextRepeat,
                Font           = new SignatureFont()
                {
                    Size = 12, FamilyName = "Arial"
                },
                Height           = 20,
                TextBottomIntent = 6,
                TextColor        = Color.WhiteSmoke,
                BackgroundColor  = Color.DarkSlateBlue,
                InnerBorder      = new Border()
                {
                    Color        = Color.LightBlue,
                    Transparency = 0.5
                },
                OuterBorder = new Border()
                {
                    Color        = Color.DarkBlue,
                    Transparency = 0.4
                }
            }
                );

            signOptions.OuterLines.Add(
                new StampLine()
            {
                Height          = 2,
                BackgroundColor = Color.White
            }
                );

            signOptions.OuterLines.Add(
                new StampLine()
            {
                Text           = $"*{signText}*",
                TextRepeatType = StampTextRepeatType.FullTextRepeat,
                TextColor      = Color.DarkSlateBlue,
                Font           = new SignatureFont()
                {
                    Size = 15
                },
                Height           = 20,
                TextBottomIntent = 8,
                InnerBorder      = new Border()
                {
                    Color = Color.DarkSlateBlue, DashStyle = DashStyle.Dot
                },
                OuterBorder = new Border()
                {
                    Color = Color.DarkSlateBlue
                },
            }
                );

            signOptions.InnerLines.Add(
                new StampLine()
            {
                Text      = signText,
                TextColor = Color.MediumVioletRed,
                Font      = new SignatureFont()
                {
                    Size = 12, Bold = true
                },
                Height = 20,
            }
                );

            QrCodeSignOptions locationOptions = GetLocationOptions(signLocation);

            signOptions.HorizontalAlignment = locationOptions.HorizontalAlignment;
            signOptions.VerticalAlignment   = locationOptions.VerticalAlignment;

            switch (signSize)
            {
            case "small":
                signOptions.Width  = signOptions.Width * 2 / 3;
                signOptions.Height = signOptions.Height * 2 / 3;
                break;

            case "large":
                signOptions.Width  = signOptions.Width * 4 / 3;
                signOptions.Height = signOptions.Height * 4 / 3;
                break;
            }


            return(signOptions);
        }