コード例 #1
0
 public static void Run()
 {
     try
     {
         // ExStart:DigitallySignature
         string pbxFile = "";
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         // Create PdfFileSignature object and bind input and output PDF files
         PdfFileSignature pdfSign = new PdfFileSignature();
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         // Create a rectangle for signature location
         System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
         // Set signature appearance
         pdfSign.SignatureAppearance = dataDir + "aspose-logo.jpg";
         // Create any of the three signature types
         PKCS1 signature = new PKCS1(pbxFile, "password"); // PKCS#1 or
         
         pdfSign.Sign(1, "Signature Reason", "Contact", "Location", true, rect, signature);
         // Save output PDF file
         pdfSign.Save(dataDir + "DigitallySignature_out.pdf");
         // ExEnd:DigitallySignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #2
0
        public static void Run()
        {
            try
            {
                // ExStart:DigitallySignature
                string pbxFile = "";
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
                // Create PdfFileSignature object and bind input and output PDF files
                PdfFileSignature pdfSign = new PdfFileSignature();
                pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
                // Create a rectangle for signature location
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                // Set signature appearance
                pdfSign.SignatureAppearance = dataDir + "aspose-logo.jpg";
                // Create any of the three signature types
                PKCS1 signature = new PKCS1(pbxFile, "password"); // PKCS#1 or

                pdfSign.Sign(1, "Signature Reason", "Contact", "Location", true, rect, signature);
                // Save output PDF file
                pdfSign.Save(dataDir + "DigitallySignature_out.pdf");
                // ExEnd:DigitallySignature
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
 public static void Run()
 {
     try
     {
         // ExStart:RemoveSignature
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         // Create PdfFileSignature object
         PdfFileSignature pdfSign = new PdfFileSignature();
         // Open PDF document
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         // Get list of signature names
         IList names = pdfSign.GetSignNames();
         // Remove all the signatures from the PDF file
         for (int index = 0; index < names.Count; index++)
         {
             pdfSign.RemoveSignature((string)names[index]);
         }
         // Save updated PDF file
         pdfSign.Save(dataDir + "RemoveSignature_out_.pdf");
         // ExEnd:RemoveSignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #4
0
        public static void AddSignatureFields()
        {
            // ExStart:AddSignatureFields
            // The path to the documents directory.
            string   dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
            Document doc     = new Document(dataDir + "inFile.pdf");
            // Create FormEditor object
            FormEditor editor = new FormEditor(doc);

            // Add signature fields
            editor.AddField(FieldType.Signature, "Signature from Alice", 1, 10, 10, 110, 110);
            editor.AddField(FieldType.Signature, "Signature from John", 1, 120, 150, 220, 250);
            editor.AddField(FieldType.Signature, "Signature from Smith", 1, 300, 200, 400, 300);
            // Save the form
            editor.Save(dataDir + "AddSignatureFields_1_out.pdf");

            Document doc2 = new Document(dataDir + "inFile2.pdf");
            // Add signature to any of the signature fields
            PdfFileSignature pdfSign = new PdfFileSignature(doc2);

            pdfSign.Sign("Signature from John", "Signature Reason", "John", "Kharkov", new PKCS1("inFile1.pdf", "password"));
            // Each time new signature is added you must save the document
            pdfSign.Save(dataDir + "AddSignatureFields_2_out.pdf");

            Document doc3 = new Document(dataDir + "FilledForm.pdf");
            // Add second signature
            PdfFileSignature pdfSign2 = new PdfFileSignature(doc3);

            pdfSign2.Sign("Signature from Alice", "Signature Reason", "Alice", "Odessa", new PKCS1(dataDir + "FilledForm - 2.pfx", "password"));
            // Each time new signature is added you must save the document
            pdfSign2.Save(dataDir + "AddSignatureFields_3_out.pdf");
            // ExEnd:AddSignatureFields
        }
コード例 #5
0
 public static void Run()
 {
     try
     {
         // ExStart:RemoveSignature                
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         // Create PdfFileSignature object
         PdfFileSignature pdfSign = new PdfFileSignature();
         // Open PDF document
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         // Get list of signature names
         IList names = pdfSign.GetSignNames();
         // Remove all the signatures from the PDF file
         for (int index = 0; index < names.Count; index++)
         {
             pdfSign.RemoveSignature((string)names[index]);
         }
         // Save updated PDF file
         pdfSign.Save(dataDir + "RemoveSignature_out.pdf");
         // ExEnd:RemoveSignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #6
0
        public static void Run()
        {
            // ExStart:HideDigitallySignedByCaption
            // The path to the documents directory.
            string dataDir   = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
            string inPfxFile = dataDir + "SampleCertificate.pfx";
            string inFile    = dataDir + "input.pdf";
            string outFile   = dataDir + "output.pdf";

            using (PdfFileSignature pdfSign = new PdfFileSignature())
            {
                pdfSign.BindPdf(inFile);
                //create a rectangle for signature location
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(310, 45, 200, 50);

                //create any of the three signature types
                PKCS7 pkcs = new PKCS7(inPfxFile, "idsrv3test");
                SignatureCustomAppearance signatureCustomAppearance = new SignatureCustomAppearance();
                signatureCustomAppearance.FontSize           = 6;
                signatureCustomAppearance.FontFamilyName     = "Times New Roman";
                signatureCustomAppearance.DigitalSignedLabel = "Signed by me";
                pkcs.CustomAppearance = signatureCustomAppearance;
                // sign the PDF file
                pdfSign.Sign(1, true, rect, pkcs);
                //save output PDF file
                pdfSign.Save(outFile);
            }
            // ExEnd:HideDigitallySignedByCaption
        }
コード例 #7
0
        public static void AddSignatureFields()
        {
            // ExStart:AddSignatureFields
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
            Document doc = new Document(dataDir + "inFile.pdf");
            // Create FormEditor object
            FormEditor editor = new FormEditor(doc);
            // Add signature fields
            editor.AddField(FieldType.Signature, "Signature from Alice", 1, 10, 10, 110, 110);
            editor.AddField(FieldType.Signature, "Signature from John", 1, 120, 150, 220, 250);
            editor.AddField(FieldType.Signature, "Signature from Smith", 1, 300, 200, 400, 300);
            // Save the form
            editor.Save(dataDir + "AddSignatureFields_1_out.pdf");

            Document doc2 = new Document(dataDir + "inFile2.pdf");
            // Add signature to any of the signature fields
            PdfFileSignature pdfSign = new PdfFileSignature(doc2);
            pdfSign.Sign("Signature from John", "Signature Reason", "John", "Kharkov", new PKCS1("inFile1.pdf", "password"));
            // Each time new signature is added you must save the document
            pdfSign.Save(dataDir + "AddSignatureFields_2_out.pdf");

            Document doc3 = new Document(dataDir + "FilledForm.pdf");
            // Add second signature
            PdfFileSignature pdfSign2 = new PdfFileSignature(doc3);
            pdfSign2.Sign("Signature from Alice", "Signature Reason", "Alice", "Odessa", new PKCS1(dataDir + "FilledForm - 2.pfx", "password"));
            // Each time new signature is added you must save the document
            pdfSign2.Save(dataDir + "AddSignatureFields_3_out.pdf");
            // ExEnd:AddSignatureFields
        }
コード例 #8
0
        private static void Run_34561_tests()
        {
            // ExStart:Run_34561_tests
            new License().SetLicense(@"E:\Aspose.Pdf.lic");
            string inSingleSignedFile      = @"C:\pdftest\PDFNEWNET_34561_SingleSigned.pdf";
            string outSingleUnsignedFile   = @"C:\pdftest\PDFNEWNET_34561_SingleUnSigned.pdf";
            string inOutSingleResignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleReSigned.pdf";

            PdfFileSignature pdfSignSingle = new PdfFileSignature();

            pdfSignSingle.BindPdf(inSingleSignedFile);
            IList  names         = pdfSignSingle.GetSignNames();
            Stream pfx           = new FileStream(@"C:\pdftest\test1.pfx", FileMode.Open);
            PKCS7  pcks          = new PKCS7(pfx, "test1");
            string sigNameSingle = names[0] as string;

            if (sigNameSingle != null && sigNameSingle != string.Empty)
            {
                pdfSignSingle.RemoveSignature(sigNameSingle, false);
                pdfSignSingle.Save(outSingleUnsignedFile);

                PdfFileSignature pdfSignSingle2 = new PdfFileSignature();
                pdfSignSingle2.BindPdf(outSingleUnsignedFile);
                pdfSignSingle2.SignatureAppearance = @"C:\pdftest\butterfly.jpg";
                pdfSignSingle2.Sign("Signature1", pcks);
                pdfSignSingle2.Save(inOutSingleResignedFile);
                pdfSignSingle2.BindPdf(inOutSingleResignedFile);
                // Assert.True(pdfSignSingle2.VerifySignature("Signature1"));
                Console.Write("Signature 1 check result : " + pdfSignSingle2.VerifySignature("Signature1").ToString() + " \n");
            }

            // Test file with multiple signatures
            string           outManyUnsignedFile   = @"C:\pdftest\PDFNEWNET_34561_ManyUnSigned.pdf";
            string           inOutManyResignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyReSigned.pdf";
            PdfFileSignature pdfSignMany           = new Aspose.Pdf.Facades.PdfFileSignature();

            IList sigNames = pdfSignMany.GetSignNames();

            foreach (string sigName in sigNames)
            {
                pdfSignMany.RemoveSignature(sigName, false);
            }

            pdfSignMany.Save(outManyUnsignedFile);

            PdfFileSignature pdfSignMany2 = new PdfFileSignature();

            pdfSignMany2.BindPdf(outManyUnsignedFile);
            pdfSignMany2.Sign("Signature1", pcks);
            pdfSignMany2.Save(inOutManyResignedFile);
            pdfSignMany2.BindPdf(inOutSingleResignedFile);
            // Assert.IsTrue(pdfSignMany2.VerifySignature("Signature1"));
            Console.Write("Signature 2 check result : " + pdfSignMany2.VerifySignature("Signature1").ToString() + " ");
            // ExEnd:Run_34561_tests
        }
コード例 #9
0
        public static void Run()
        {
            try
            {
                // ExStart:DigitallySign
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
                string pbxFile = "";
                string inFile  = dataDir + @"DigitallySign.pdf";
                string outFile = dataDir + @"DigitallySign_out_.pdf";
                using (Document document = new Document(inFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        PKCS7                    pkcs            = new PKCS7(pbxFile, "WebSales"); // Use PKCS7/PKCS7Detached objects
                        DocMDPSignature          docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                        System.Drawing.Rectangle rect            = new System.Drawing.Rectangle(100, 100, 200, 100);
                        // Set signature appearance
                        signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                        // Create any of the three signature types
                        signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                        // Save output PDF file
                        signature.Save(outFile);
                    }
                }

                using (Document document = new Document(outFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        IList sigNames = signature.GetSignNames();
                        if (sigNames.Count > 0)                                                                     // Any signatures?
                        {
                            if (signature.VerifySigned(sigNames[0] as string))                                      // Verify first one
                            {
                                if (signature.IsCertified)                                                          // Certified?
                                {
                                    if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                    {
                                        // Do something
                                    }
                                }
                            }
                        }
                    }
                }
                // ExEnd:DigitallySign
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #10
0
        public static void Run()
        {
            try
            {
                // ExStart:DigitallySign
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
                string pbxFile = "";
                string inFile = dataDir + @"DigitallySign.pdf";
                string outFile = dataDir + @"DigitallySign_out.pdf";
                using (Document document = new Document(inFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        PKCS7 pkcs = new PKCS7(pbxFile, "WebSales"); // Use PKCS7/PKCS7Detached objects
                        DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                        // Set signature appearance
                        signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                        // Create any of the three signature types
                        signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                        // Save output PDF file
                        signature.Save(outFile);
                    }
                }

                using (Document document = new Document(outFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        IList sigNames = signature.GetSignNames();
                        if (sigNames.Count > 0) // Any signatures?
                        {
                            if (signature.VerifySigned(sigNames[0] as string)) // Verify first one
                            {
                                if (signature.IsCertified) // Certified?
                                {
                                    if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                    {
                                        // Do something
                                    }
                                }
                            }
                        }
                    }
                }
                // ExEnd:DigitallySign
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #11
0
        private static void Run_34561_tests()
        {
            // ExStart:Run_34561_tests
            new License().SetLicense(@"E:\Aspose.Pdf.lic");
            string inSingleSignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleSigned.pdf";
            string outSingleUnsignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleUnSigned.pdf";
            string inOutSingleResignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleReSigned.pdf";

            PdfFileSignature pdfSignSingle = new PdfFileSignature();
            pdfSignSingle.BindPdf(inSingleSignedFile);
            IList names = pdfSignSingle.GetSignNames();
            Stream pfx = new FileStream(@"C:\pdftest\test1.pfx", FileMode.Open);
            PKCS7 pcks = new PKCS7(pfx, "test1");
            string sigNameSingle = names[0] as string;
            if (sigNameSingle != null && sigNameSingle != string.Empty)
            {
                pdfSignSingle.RemoveSignature(sigNameSingle, false);
                pdfSignSingle.Save(outSingleUnsignedFile);

                PdfFileSignature pdfSignSingle2 = new PdfFileSignature();
                pdfSignSingle2.BindPdf(outSingleUnsignedFile);
                pdfSignSingle2.SignatureAppearance = @"C:\pdftest\butterfly.jpg";
                pdfSignSingle2.Sign("Signature1", pcks);
                pdfSignSingle2.Save(inOutSingleResignedFile);
                pdfSignSingle2.BindPdf(inOutSingleResignedFile);
                // Assert.True(pdfSignSingle2.VerifySignature("Signature1"));
                Console.Write("Signature 1 check result : " + pdfSignSingle2.VerifySignature("Signature1").ToString() + " \n");
            }

            // Test file with multiple signatures         
            string outManyUnsignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyUnSigned.pdf";
            string inOutManyResignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyReSigned.pdf";
            PdfFileSignature pdfSignMany = new Aspose.Pdf.Facades.PdfFileSignature();

            IList sigNames = pdfSignMany.GetSignNames();
            foreach (string sigName in sigNames)
            {
                pdfSignMany.RemoveSignature(sigName, false);
            }

            pdfSignMany.Save(outManyUnsignedFile);

            PdfFileSignature pdfSignMany2 = new PdfFileSignature();
            pdfSignMany2.BindPdf(outManyUnsignedFile);
            pdfSignMany2.Sign("Signature1", pcks);
            pdfSignMany2.Save(inOutManyResignedFile);
            pdfSignMany2.BindPdf(inOutSingleResignedFile);
            // Assert.IsTrue(pdfSignMany2.VerifySignature("Signature1"));
            Console.Write("Signature 2 check result : " + pdfSignMany2.VerifySignature("Signature1").ToString() + " ");
            // ExEnd:Run_34561_tests
        }
コード例 #12
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string inFile  = dataDir + @"input.pdf";
            string outFile = dataDir + @"output.pdf";

            using (Document document = new Document(inFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    PKCS7                    pkcs            = new PKCS7(@"c:\test.pfx", "WebSales"); // Use PKCS7/PKCS7Detached objects
                    DocMDPSignature          docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                    System.Drawing.Rectangle rect            = new System.Drawing.Rectangle(100, 100, 200, 100);
                    //set signature appearance
                    signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                    //create any of the three signature types
                    signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                    //save output PDF file
                    signature.Save(outFile);
                }
            }

            using (Document document = new Document(outFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    IList sigNames = signature.GetSignNames();
                    if (sigNames.Count > 0)                                                                     // Any signatures?
                    {
                        if (signature.VerifySigned(sigNames[0] as string))                                      // Verify first one
                        {
                            if (signature.IsCertified)                                                          // Certified?
                            {
                                if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                {
                                    // Do something
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string inFile = dataDir+ @"input.pdf";
            string outFile = dataDir + @"output.pdf";
            using (Document document = new Document(inFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    PKCS7 pkcs = new PKCS7(@"c:\test.pfx", "WebSales"); // Use PKCS7/PKCS7Detached objects
                    DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                    //set signature appearance
                    signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                    //create any of the three signature types
                    signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                    //save output PDF file
                    signature.Save(outFile);
                }
            }

            using (Document document = new Document(outFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    IList sigNames = signature.GetSignNames();
                    if (sigNames.Count > 0) // Any signatures?
                    {
                        if (signature.VerifySigned(sigNames[0] as string)) // Verify first one
                        {
                            if (signature.IsCertified) // Certified?
                            {
                                if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                {
                                    // Do something
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #14
0
 public static void Run()
 {
     // ExStart:DigitallySignWithTimeStamp
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
     string pfxFile = "";
     using (Document document = new Document(dataDir + @"DigitallySign.pdf"))
     {
         using (PdfFileSignature signature = new PdfFileSignature(document))
         {
             PKCS7 pkcs = new PKCS7(pfxFile, "pfx_password");
             TimestampSettings timestampSettings = new TimestampSettings("https:\\your_timestamp_settings", "user:password"); // User/Password can be omitted
             pkcs.TimestampSettings = timestampSettings;
             System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
             // Create any of the three signature types
             signature.Sign(1, "Signature Reason", "Contact", "Location", true, rect, pkcs);
             // Save output PDF file
             signature.Save(dataDir + "DigitallySignWithTimeStamp_out.pdf");
         }
     }
     // ExEnd:DigitallySignWithTimeStamp
 }
コード例 #15
0
        public static void Run()
        {
            // ExStart:DigitallySignWithTimeStamp
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
            string pfxFile = "";

            using (Document document = new Document(dataDir + @"DigitallySign.pdf"))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    PKCS7             pkcs = new PKCS7(pfxFile, "pfx_password");
                    TimestampSettings timestampSettings = new TimestampSettings("https:\\your_timestamp_settings", "user:password"); // User/Password can be omitted
                    pkcs.TimestampSettings = timestampSettings;
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                    // Create any of the three signature types
                    signature.Sign(1, "Signature Reason", "Contact", "Location", true, rect, pkcs);
                    // Save output PDF file
                    signature.Save(dataDir + "DigitallySignWithTimeStamp_out_.pdf");
                }
            }
            // ExEnd:DigitallySignWithTimeStamp
        }