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.

Fri Aug 25, 2023 6:08 am

Hello Team,

I have used the below code to protect the PDF files with a password for opening. Password protection is working in windows machines or android mobile devices. But if I try to open the same PDF in iOS devices, PDF opens without asking for any password.

pdfFile.FileInfo.Version = PdfVersion.Version1_7;
pdfFile.Security.Encrypt(password, "", PdfPermissionsFlags.Default, PdfEncryptionKeySize.Key256Bit);
MemoryStream pdfStream = new MemoryStream();
pdfFile.SaveToStream(pdfStream, Spire.Pdf.FileFormat.PDF);
pdfFile.Close();
pdfFile.Dispose();
return new MemoryStream(pdfStream.ToArray());

Current version of Spire.Office - 6.12.1

Thanks and Regards,
Venkat

VenkatUnisys
 
Posts: 4
Joined: Fri Aug 25, 2023 5:51 am

Fri Aug 25, 2023 7:57 am

Hi Venkat,

Thanks for your feedback.
We recommend upgrading to our latest version, as we have made adjustments to the encryption method. The newer version includes improvements and enhancements that may resolve the issue you are facing. Please update your installation to the latest version and retest the encryption feature.

To assist you further, we suggest referring to the following code snippet as a guide for encrypting your PDF documents:
Code: Select all
            //Load a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"Encryption.pdf");
            //Set the userPassword
            string userPassword = "user";
            //Set the ownerPassword
            string ownerPassword = "owner";
            //Create a PdfSecurityPolicy
            PdfSecurityPolicy securityPolicy = new PdfPasswordSecurityPolicy(userPassword, ownerPassword);
            // Gets the sets encryption algorithm.
            securityPolicy.EncryptMetadata = false;
            // Set encryption algorithm.
            securityPolicy.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES_128;
            //Set the document's permission flags
            securityPolicy.DocumentPrivilege = PdfDocumentPrivilege.AllowAll;
            // Set permissions that do not allow printing.
            securityPolicy.DocumentPrivilege.AllowPrint = false;
            //Encrypt
            doc.Encrypt(securityPolicy);
         
            //Save pdf file.
            doc.SaveToFile("Encryption-result.pdf");
            doc.Close();



After testing the new version and following the updated encryption approach, if you encounter same issue, please provide us with the specific PDF documents and details about your project type. This information will help us investigate the problem more effectively and provide you with appropriate solutions.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Sun Aug 27, 2023 8:05 am

Thanks Team for the reply will check your solution and get back soon.

VenkatUnisys
 
Posts: 4
Joined: Fri Aug 25, 2023 5:51 am

Mon Aug 28, 2023 1:40 am

Hi,

Thanks for your reply.
If there are any issues after testing, please feel free to contact us. We are here to assist you.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF