private StampLine DrawOuterLineForSquare(StampXmlEntity stampData)
        {
            StampLine line = new StampLine();

            line.BackgroundColor    = getColor(stampData.backgroundColor);
            line.OuterBorder.Color  = getColor(stampData.strokeColor);
            line.OuterBorder.Weight = stampData.strokeWidth;
            line.InnerBorder.Color  = getColor(stampData.backgroundColor);
            line.InnerBorder.Weight = 0.5;
            line.Height             = 1;
            return(line);
        }
        private StampLine PrepareHarisontalLine(StampXmlEntity stampData, string text, int reductionSize)
        {
            StampLine squareLine = new StampLine
            {
                Text = text
            };

            squareLine.Font.Size      = stampData.fontSize / reductionSize;
            squareLine.Font.Bold      = stampData.bold;
            squareLine.Font.Italic    = stampData.italic;
            squareLine.Font.Underline = stampData.underline;
            squareLine.TextColor      = getColor(stampData.textColor);

            return(squareLine);
        }
        /// <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);
        }
Beispiel #4
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}.");
            }
        }
        private StampLine DrawOuterCircle(StampXmlEntity stampData, string innerBorderColor, string text, int height, int reductionSize)
        {
            StampLine line = new StampLine();

            line.BackgroundColor    = getColor(stampData.backgroundColor);
            line.OuterBorder.Color  = getColor(stampData.strokeColor);
            line.OuterBorder.Weight = stampData.strokeWidth;
            line.InnerBorder.Color  = getColor(innerBorderColor);
            line.InnerBorder.Weight = 0.5;
            line.Text             = text;
            line.Font.Bold        = stampData.bold;
            line.Font.Italic      = stampData.italic;
            line.Font.Underline   = stampData.underline;
            line.Height           = height;
            line.Font.Size        = stampData.fontSize / reductionSize;
            line.TextColor        = getColor(stampData.textColor);
            line.TextBottomIntent = (height / 2) - (stampData.fontSize / 2);
            line.TextRepeatType   = StampTextRepeatType.None;
            return(line);
        }