Пример #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:SuppressLocationAndReason
                // The path to the documents directory.
                string dataDir   = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
                string inPfxFile = dataDir + "certificate.pfx";
                string inFile    = dataDir + "input.pdf";
                string outFile   = dataDir + "output.pdf";
                using (Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature())
                {
                    pdfSign.BindPdf(inFile);
                    //create a rectangle for signature location
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);

                    //create any of the three signature types
                    PKCS1 signature = new PKCS1(inPfxFile, "12345");
                    // sign the PDF file
                    pdfSign.Sign(1, "", "Contact", "", true, rect, signature);
                    //save output PDF file
                    pdfSign.Save(outFile);
                }
                // ExEnd:SuppressLocationAndReason
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
        public static void Run()
        {
            try
            {
                // ExStart:RemoveRights
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
                string input   = dataDir + "DigitallySign.pdf";
                using (PdfFileSignature pdfSign = new PdfFileSignature())
                {
                    pdfSign.BindPdf(input);
                    if (pdfSign.ContainsUsageRights())
                    {
                        pdfSign.RemoveUsageRights();
                    }

                    pdfSign.Document.Save(dataDir + "RemoveRights_out_.pdf");
                }
                // ExEnd:RemoveRights
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #4
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
        }
Пример #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:EncryptFile
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
            // Create PdfFileSecurity object
            PdfFileSecurity fileSecurity = new PdfFileSecurity();

            fileSecurity.BindPdf(dataDir + "Encrypt.pdf");
            // Encrypt file using 256-bit encryption
            fileSecurity.EncryptFile("user", "owner", DocumentPrivilege.Print, KeySize.x256, Algorithm.AES);
            fileSecurity.Save(dataDir + "Encrypt_out.pdf");
            // ExEnd:EncryptFile
        }
Пример #7
0
        public static void Run()
        {
            // ExStart:DecryptFile
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
            // Create PdfFileSecurity object
            PdfFileSecurity fileSecurity = new PdfFileSecurity();

            fileSecurity.BindPdf(dataDir + "Decrypt.pdf");
            // Decrypt PDF document
            fileSecurity.DecryptFile("owner");
            fileSecurity.Save(dataDir + "DecryptFile_out.pdf");
            // ExEnd:DecryptFile
        }
Пример #8
0
        public static void VerifyPDFSigned()
        {
            // ExStart:VerifyPDFSigned
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();

            PdfFileSignature pdfSign = new PdfFileSignature();

            pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
            pdfSign.ContainsSignature();
            // Any signatures?
            pdfSign.Close();
            // ExEnd:VerifyPDFSigned
        }
Пример #9
0
        public static void Run()
        {
            // ExStart:ChangeFilePassword
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
            // Create PdfFileSecurity object
            PdfFileSecurity fileSecurity = new PdfFileSecurity();

            fileSecurity.BindPdf(dataDir + "ChangePassword.pdf");

            // Change password
            fileSecurity.ChangePassword("owner", "newuserpassword", "newownerpassword");
            fileSecurity.Save(dataDir + "ChangeFilePassword_out.pdf");
            // ExEnd:ChangeFilePassword
        }
Пример #10
0
        public static void Run()
        {
            try
            {
                // ExStart:ChangeLanguageInDigitalSignText
                // The path to the documents directory.
                string dataDir   = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
                string inPfxFile = dataDir + "certificate.pfx";
                string inFile    = dataDir + "input.pdf";
                string outFile   = dataDir + "output.pdf";

                using (Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.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, "12345");
                    pkcs.Reason      = "Pruebas Firma";
                    pkcs.ContactInfo = "Contacto Pruebas";
                    pkcs.Location    = "Población (Provincia)";
                    pkcs.Date        = DateTime.Now;
                    SignatureCustomAppearance signatureCustomAppearance = new SignatureCustomAppearance();
                    signatureCustomAppearance.DateSignedAtLabel  = "Fecha";
                    signatureCustomAppearance.DigitalSignedLabel = "Digitalmente firmado por";
                    signatureCustomAppearance.ReasonLabel        = "Razón";
                    signatureCustomAppearance.LocationLabel      = "Localización";
                    signatureCustomAppearance.FontFamilyName     = "Arial";
                    signatureCustomAppearance.FontSize           = 10d;
                    signatureCustomAppearance.Culture            = CultureInfo.InvariantCulture;
                    signatureCustomAppearance.DateTimeFormat     = "yyyy.MM.dd HH:mm:ss";
                    pkcs.CustomAppearance = signatureCustomAppearance;
                    // sign the PDF file
                    pdfSign.Sign(1, true, rect, pkcs);
                    //save output PDF file
                    pdfSign.Save(outFile);

                    // ExEnd:ChangeLanguageInDigitalSignText
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #11
0
 public static void Run()
 {
     try
     {
         // ExStart:VerifyValidSignature
         // The path to the documents directory.
         string           dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         PdfFileSignature pdfSign = new PdfFileSignature();
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         if (pdfSign.VerifySignature("Signature1"))
         {
             Console.WriteLine("Signature Verified");
         }
         // ExEnd:VerifyValidSignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
 public static void Run()
 {
     try
     {
         // ExStart:ExtractSignatureInfo
         // The path to the documents directory.
         string dataDir   = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         string input     = dataDir + "DigitallySign.pdf";
         string pkcs1File = "";
         using (PdfFileSignature pdfFileSignature = new PdfFileSignature())
         {
             pdfFileSignature.BindPdf(input);
             IList <string> sigNames = pdfFileSignature.GetSignNames();
             if (sigNames.Count > 0)
             {
                 string sigName = sigNames[0] as string;
                 if (string.IsNullOrEmpty(sigName))
                 {
                     Stream cerStream = pdfFileSignature.ExtractCertificate(sigName);
                     if (cerStream != null)
                     {
                         using (cerStream)
                         {
                             byte[] bytes = new byte[cerStream.Length];
                             using (FileStream fs = new FileStream(dataDir + pkcs1File, FileMode.CreateNew))
                             {
                                 cerStream.Read(bytes, 0, bytes.Length);
                                 fs.Write(bytes, 0, bytes.Length);
                             }
                         }
                     }
                 }
             }
         }
         // ExEnd:ExtractSignatureInfo
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
        public static void Run()
        {
            // ExStart:SetPrivilegesOnFile
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();

            // Create DocumentPrivileges object
            DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;

            privilege.ChangeAllowLevel = 1;
            privilege.AllowPrint       = true;
            privilege.AllowCopy        = true;

            // Create PdfFileSecurity object
            PdfFileSecurity fileSecurity = new PdfFileSecurity();

            fileSecurity.BindPdf(dataDir + "input.pdf");

            // Set document privileges
            fileSecurity.SetPrivilege(privilege);
            fileSecurity.Save(dataDir + "SetPrivilegesOnFile_out.pdf");
            // ExEnd:SetPrivilegesOnFile
        }
Пример #14
0
 public static void Run()
 {
     try
     {
         // ExStart:ExtractImages
         // The path to the documents directory.
         string   dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         string   input   = dataDir + "DigitallySign.pdf";
         Document doc     = new Document(input);
         using (PdfFileSignature signature = new PdfFileSignature(doc))
         {
             if (signature.ContainsSignature())
             {
                 foreach (string sigName in signature.GetSignNames())
                 {
                     string outFile = dataDir + "ExtractImages_out.jpg";
                     using (Stream imageStream = signature.ExtractImage(sigName))
                     {
                         if (imageStream != null)
                         {
                             using (System.Drawing.Image image = Bitmap.FromStream(imageStream))
                             {
                                 image.Save(outFile, ImageFormat.Jpeg);
                             }
                         }
                     }
                 }
             }
         }
         // ExEnd:ExtractImages
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }