Пример #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         if (!String.IsNullOrEmpty(txtLicense.Text) && !lnkPDF.Text.Equals("Select a PDF File To Encrypt"))
         {
             Document document = new Document(lnkPDF.Text);
             // Apply restrictions on all privileges
             DocumentPrivilege documentPrivilege = rdoForbid.Checked == true ? DocumentPrivilege.ForbidAll : DocumentPrivilege.AllowAll;
             documentPrivilege.AllowScreenReaders     = chkScreenReaders.Checked;
             documentPrivilege.AllowAssembly          = chkAssembly.Checked;
             documentPrivilege.AllowCopy              = chkCopy.Checked;
             documentPrivilege.AllowModifyAnnotations = chkModifyAnnotations.Checked;
             documentPrivilege.AllowModifyContents    = chkModifyContent.Checked;
             documentPrivilege.AllowPrint             = chkPrint.Checked;
             // Encrypt the file with User and Owner password.
             // Need to set the password, so that once the user views the file with user password
             document.Encrypt(txtUser.Text, txtOwner.Text, documentPrivilege, CryptoAlgorithm.AESx128, false);
             // Save updated document
             document.Save("SetPrivileges_out.pdf");
             MessageBox.Show("PDF has been encrypted successfully.", "Success");
         }
         else
         {
             MessageBox.Show("Please select License and PDF file first.", "No File Selected");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
     }
 }
        public void PutPrivilegesTest()
        {
            string name = "4pages.pdf";

            UploadFile(name, name);

            DocumentPrivilege documentPrivilege = new DocumentPrivilege()
            {
                AllowCopy  = false,
                AllowPrint = false
            };

            var response = PdfApi.PutPrivileges(name, documentPrivilege, folder: TempFolder);

            Assert.That(response.Code, Is.EqualTo(200));
        }
Пример #3
0
        private MemoryStream AddWatermarkToFile(Document pdfDocument, ref PdfFileStamp pdfStamp, string sUserName, DateTime dtCurrentDate, string sCompany)
        {
            string sTextDate = dtCurrentDate.ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

            FormattedText wtext = new FormattedText("Confidential", new FontColor(220, 20, 60), new FontColor(255, 255, 255),
                                                    Aspose.Pdf.Facades.FontStyle.HelveticaBold,
                                                    EncodingType.Winansi, true, 35);

            wtext.AddNewLineText(sUserName, 5);
            wtext.AddNewLineText(sTextDate, 5);

            int nPageCount = 1;

            foreach (Aspose.Pdf.Page pg in pdfDocument.Pages)
            {
                //get the page size position for each page
                Aspose.Pdf.Rectangle rtPage = pg.TrimBox;
                AddWatermarkToPage(rtPage.Width, rtPage.Height, pg, sUserName, sTextDate);

                nPageCount++;
            }

            MemoryStream outStream = new MemoryStream();
            //save updated PDF file
            DocumentPrivilege pv = null;

            pv = DocumentPrivilege.AllowAll;

            pv.ChangeAllowLevel = 0;
            pv.CopyAllowLevel   = 1;
            pv.PrintAllowLevel  = 2;

            pdfStamp.Document.Encrypt("", new Guid().ToString(), pv, CryptoAlgorithm.RC4x128, false);

            pdfStamp.Save(outStream);

            return(outStream);
        }
        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
        }
Пример #5
0
        public static void Run()
        {
            // ExStart:SetPrivileges
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();

            // Load a source PDF file
            using (Document document = new Document(dataDir + "input.pdf"))
            {
                // Instantiate Document Privileges object
                // Apply restrictions on all privileges
                DocumentPrivilege documentPrivilege = DocumentPrivilege.ForbidAll;
                // Only allow screen reading
                documentPrivilege.AllowScreenReaders = true;
                // Encrypt the file with User and Owner password.
                // Need to set the password, so that once the user views the file with user password,
                // Only screen reading option is enabled
                document.Encrypt("user", "owner", documentPrivilege, CryptoAlgorithm.AESx128, false);
                // Save updated document
                document.Save(dataDir + "SetPrivileges_out.pdf");
            }
            // ExEnd:SetPrivileges
        }