Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Oct 13, 2021 9:42 am

We recently upgraded from a very old version of Spire.pdf to the latest one and now run into an issue that we cannot set securityparams anymore.
They all seem to be read only.
Code: Select all
       //
        // Summary:
        //     Gets the owner password.
        public string OwnerPassword { get; }
        //
        // Summary:
        //     Gets the user password.
        public string UserPassword { get; }
        //
        // Summary:
        //     Indicate whether this pdf document was encrypted originally or not.
        public bool OriginalEncrypt { get; }
        //
        // Summary:
        //     Gets the document's permission flags
        public PdfPermissionsFlags Permissions { get; }
        //
        // Summary:
        //     Gets the size of the key.
        public PdfEncryptionKeySize KeySize { get; }


How do i set a password on my pdf? The tutorial still let you set this properties so that doesn't really help.

DigitallHealth
 
Posts: 3
Joined: Fri Oct 08, 2021 2:56 pm

Wed Oct 13, 2021 10:00 am

Hello Hans,

Thanks for your inquiry.
Please refer to the following code to set pdf security properties.
Code: Select all
 
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(pdffile);
            //Encrypt
            PdfEncryptionKeySize keySize = PdfEncryptionKeySize.Key128Bit;
            string openPassword = "e-iceblue";
            string permissionPassword = "test";
            PdfPermissionsFlags flags = PdfPermissionsFlags.Print | PdfPermissionsFlags.FillFields;
            doc.Security.Encrypt(openPassword, permissionPassword, flags, keySize);

            //Save pdf file.
            doc.SaveToFile("Encryption-result.pdf");
            doc.Close();

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Wed Oct 13, 2021 10:11 am

Thanks for your quick reply.
The permissionpassword is the same as what in the old version was called OwnerPassword?

DigitallHealth
 
Posts: 3
Joined: Fri Oct 08, 2021 2:56 pm

Thu Oct 14, 2021 1:23 am

Hello Hans,

Yes, it is. Sorry I didn't go into detail about the properties of the new method. Please check out the details below.
Code: Select all
doc.Security.Encrypt(UserPassword/OpenPassword, OwnerPassword/permissionPassword, pdfPermissionsFlags, pdfEncryptionKeySize );


Should you have any questions, please contact me.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

cron