Password Protect PDF - Aspose.Words

A few months ago I asked if Aspose.Words could create password encrypted pdf’s directly and the answer was no. But that you were working on this feature, and it was possible that it would be out in 2 or 3 months. Is there any status update for when you expect this feature to be rolled out?

Hi

Thanks for your request. Unfortunately, this feature is still unavailable. This is the issue #7880 in our defect database. You will be notified as soon as it is resolved.

Best regards.

The issues you have found earlier (filed as 7880) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(12)

aspose.notifier:

The issues you have found earlier (filed as 7880) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(12)

Is this feature now available? How would you use it in the Java version?

Hi Matteo,

Thanks for your inquiry. Yes, this feature is available in latest version of Aspose.Words for Java v13.7.0.

The PdfEncryptionDetails class contains details for encrypting and access permissions for a PDF document. The PdfEncryptionDetails.setPermissions method specifies the operations that are allowed to a user on an encrypted PDF document. The default value is DisallowAll. Please read the Pdf Permissions from here:
https://reference.aspose.com/words/java/com.aspose.words/pdfencryptiondetails

PdfEncryptionDetails.setOwnerPassword: Specifies the owner password for the encrypted PDF document.

Please check following code example for your kind reference. Hope this helps you.

Document doc = new Document(getMyDir() + "Rendering.doc");
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Create encryption details and set owner password.
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails("password1", "password", PdfEncryptionAlgorithm.RC_4_128);
// Start by disallowing all permissions.
encryptionDetails.setPermissions(PdfPermissions.DISALLOW_ALL);
// Extend permissions to allow editing or modifying annotations.
encryptionDetails.setPermissions(PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);
saveOptions.setEncryptionDetails(encryptionDetails);
// Render the document to PDF format with the specified permissions.
doc.save(getMyDir() + "Rendering.SpecifyPermissions Out.pdf", saveOptions);

That’s exactly what I tried to do, see my other post.

The problem is that, if I apply such protection, when I open the PDF in Adobe Acrobat Reader, it asks me for a password also to simply open it, and I do not want this, I would just want the password asked to unlock the locked features.

Is this possible?

Hi Matteo,

Thanks for your inquiry. Yes, it is possible. Please do not put the user password in PdfEncryptionDetails constructor. Please see the highlighted section in the following code example. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.doc");
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Create encryption details and set owner password.
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails("", "password", PdfEncryptionAlgorithm.RC_4_128);
// Start by disallowing all permissions.
encryptionDetails.setPermissions(PdfPermissions.DISALLOW_ALL);
encryptionDetails.setPermissions(PdfPermissions.PRINTING);
saveOptions.setEncryptionDetails(encryptionDetails);
// Render the document to PDF format with the specified permissions.
doc.save(MyDir + "Out.pdf", saveOptions);

That works, thank you.

If I may suggest, you should also put this example in your docs, so that another user can find out quickly how to protect the PDF without a password prompt each time.

Hi Matteo,

Thanks for your feedback and suggestion. We will include this code example in documentation. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hi Matteo,

Further to my last post, we have added following task in our issue tracking system to add the requested code example in documentation. We will update you via this forum thread once this code example is available in documentation.

WORDSNET-8712 : Add an example which demonstrates how to add PDF encryption without any user password

The issues you have found earlier (filed as WORDSNET-8712) have been fixed in this Aspose.Words for .NET 20.4 update and this Aspose.Words for Java 20.4 update.