Exemplo n.º 1
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string outputFileName = "SignSignatureField.pdf";

            using (PdfDocument pdf = new PdfDocument(@"..\Sample Data\SignatureFields.pdf"))
            {
                // IMPORTANT:
                // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password.
                // Without the change the sample will not work.

                PdfSignatureField field   = pdf.GetControl("Signature2") as PdfSignatureField;
                PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password")
                {
                    DigestAlgorithm = PdfDigestAlgorithm.Sha256,
                    Format          = PdfSignatureFormat.Pkcs7Detached,
                    Field           = field,
                    Reason          = "Testing field signing",
                    Location        = "My workplace",
                    ContactInfo     = "*****@*****.**"
                };

                pdf.SignAndSave(options, outputFileName);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Exemplo n.º 2
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string outputFileName = "SignDocument.pdf";

            using (PdfDocument pdf = new PdfDocument("Sample data/jpeg.pdf"))
            {
                // IMPORTANT:
                // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password.
                // Without the change the sample will not work.

                PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password")
                {
                    DigestAlgorithm = PdfDigestAlgorithm.Sha256,
                    Format          = PdfSignatureFormat.Pkcs7Detached,
                    Reason          = "Testing digital signatures",
                    Location        = "My workplace",
                    ContactInfo     = "*****@*****.**"
                };

                pdf.SignAndSave(options, outputFileName);
            }

            Process.Start(outputFileName);
        }
Exemplo n.º 3
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string outputFileName = "SignSignatureFieldUsingCustomStyle.pdf";

            using (PdfDocument pdf = new PdfDocument(@"..\Sample Data\SignatureFields.pdf"))
            {
                // IMPORTANT:
                // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password.
                // Without the change the sample will not work.

                PdfSignatureField field = pdf.GetControl("Control") as PdfSignatureField;
                field.BackgroundColor = new PdfGrayColor(80);

                PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password")
                {
                    DigestAlgorithm = PdfDigestAlgorithm.Sha256,
                    Format          = PdfSignatureFormat.Pkcs7Detached,
                    Field           = field,
                    Reason          = "Testing field styles",
                    Location        = "My workplace",
                    ContactInfo     = "*****@*****.**"
                };

                PdfSignatureAppearanceOptions appearance = options.Appearance;
                appearance.IncludeDate = false;
                appearance.IncludeDistinguishedName = false;

                appearance.Image         = pdf.AddImage(@"..\Sample Data\ammerland.jpg");
                appearance.Font          = pdf.AddFont(PdfBuiltInFont.Courier);
                appearance.FontSize      = 0; // calculate font size automatically
                appearance.FontColor     = new PdfRgbColor(0, 0, 255);
                appearance.TextAlignment = PdfSignatureTextAlignment.Right;

                appearance.NameLabel     = "Digital signiert von";
                appearance.ReasonLabel   = "Grund:";
                appearance.LocationLabel = "Ort:";

                pdf.SignAndSave(options, outputFileName);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "SignSignatureFieldWithLock.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                var page = pdf.Pages[0];

                var first = page.AddSignatureField("first", 100, 100, 200, 50);
                // when the first field is signed, fields with "some_text_field" and
                // "some_checkbox" names will be locked for editing
                first.Lock = PdfSignatureFieldLock.CreateLockFields("some_text_field", "some_checkbox");

                var second = page.AddSignatureField("second", 100, 200, 200, 50);
                // when the second field is signed, all fields will be locked for editing
                second.Lock = PdfSignatureFieldLock.CreateLockAll();

                // IMPORTANT:
                // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password.
                // Without the change the sample will not work.
                PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password")
                {
                    DigestAlgorithm = PdfDigestAlgorithm.Sha256,
                    Format          = PdfSignatureFormat.Pkcs7Detached,
                    Field           = first,
                    Type            = PdfSignatureType.AuthorFormFillingAllowed,
                    Reason          = "Testing field locking",
                    Location        = "My workplace",
                    ContactInfo     = "*****@*****.**"
                };

                pdf.SignAndSave(options, pathToFile);
            }

            Process.Start(pathToFile);
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string outputFileName = "SignSignatureFieldUsingCustomStyle.pdf";

            using (PdfDocument pdf = new PdfDocument("Sample data/SignatureFields.pdf"))
            {
                // IMPORTANT:
                // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password.
                // Without the change the sample will not work.

                PdfSignatureField field   = pdf.GetControl("Control") as PdfSignatureField;
                PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password")
                {
                    DigestAlgorithm = PdfDigestAlgorithm.Sha256,
                    Format          = PdfSignatureFormat.Pkcs7Detached,
                    Field           = field,
                    Reason          = "Testing field styles",
                    Location        = "My workplace",
                    ContactInfo     = "*****@*****.**"
                };

                options.Appearance.IncludeDate = false;
                options.Appearance.IncludeDistinguishedName = false;

                options.Appearance.NameLabel     = "Digital signiert von";
                options.Appearance.ReasonLabel   = "Grund:";
                options.Appearance.LocationLabel = "Ort:";

                pdf.SignAndSave(options, outputFileName);
            }

            Process.Start(outputFileName);
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string outputFileName = "SignDocumentEmbedTimestamp.pdf";

            using (PdfDocument pdf = new PdfDocument("Sample data/jpeg.pdf"))
            {
                // IMPORTANT:
                // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password.
                // Without the change the sample will not work.

                PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password")
                {
                    DigestAlgorithm = PdfDigestAlgorithm.Sha256,
                    Format          = PdfSignatureFormat.CadesDetached,
                    Reason          = "Testing timestamp embedding",
                    Location        = "My workplace",
                    ContactInfo     = "*****@*****.**"
                };

                // Replace the following test URL with your Timestamp Authority URL
                options.Timestamp.AuthorityUrl = new Uri("http://tsa.starfieldtech.com/");

                // Specify username and password if your Timestamp Authority requires authentication
                options.Timestamp.Username = null;
                options.Timestamp.Password = null;

                pdf.SignAndSave(options, outputFileName);
            }

            Process.Start(outputFileName);
        }