JAVA Could not save word to pdf by setting PdfEncryptionDetails permissions

Dear support,

I try to save an word to pdf file, but I need to set the pdf only printable without other permissions, and I refer to the sample provided by your official website. It can run on my local windows PC with 32G ram smoothly. But after deploy to my Linux server with 8G ram and try save the same word file to pdf, the server will has no response and failed. Could you suggest why?

 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.writeln("Hello world!");

 // Extend permissions to allow the editing of annotations.
 PdfEncryptionDetails encryptionDetails =
         new PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY);

 // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
 // to modify how that method converts the document to .PDF.
 PdfSaveOptions saveOptions = new PdfSaveOptions();

 // Enable encryption via the "EncryptionDetails" property.
 saveOptions.setEncryptionDetails(encryptionDetails);

 // When we open this document, we will need to provide the password before accessing its contents.
 doc.save(getArtifactsDir() + "PdfSaveOptions.EncryptionPermissions.pdf", saveOptions);

Regards

@larryzeng Unfortunately, I cannot reproduce the problem on my side using the latest 23.9 version of Aspose.Words for Java. Could you please try using the latest version on your side and let us know if the problem still persist.
Does Aspose.Words throw any exceptions in your Linux environment? If so, please provide full stack trace of the exception and specify version of Aspose.Words you use.

I am using Aspose 23.5 version. and no any exception throws. And I try use iText library to set the permission, it could success on my linux server. Looks like iText support setting encryptionType parameter, however I could not find on Aspose side.

PdfReader reader = new PdfReader(new FileInputStream(filePath));
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFilePath));
stamper.setEncryption(PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA, "", "", PdfWriter.ALLOW_PRINTING);
stamper.close();
reader.close();

And iText support setting empty owner password. But Aspose could not.

@larryzeng There is no sense encrypting document with empty user and owner passwords. Aspose.Words throws an exception if you attempt to encrypt PDF document without specifying either a user or an owner password.

I want to just allow Printing for the PDF, can it retrieve it without using PdfEncryptionDetails by setting the password? I think the encryption cause the performance issue on my Linux server.

@larryzeng You can use the following code to allow only printing:

Document doc = new Document("C:\\Temp\\in.docx");
        
PdfSaveOptions opt = new PdfSaveOptions();
opt.setEncryptionDetails(new PdfEncryptionDetails("", "ownerpass"));
opt.getEncryptionDetails().setPermissions(PdfPermissions.DISALLOW_ALL | PdfPermissions.PRINTING);
        
doc.save("C:\\Temp\\out.pdf", opt);

Unfortunately, I cannot reproduce performance issues on my side.

Yes, I did exactly this way to make the pdf only printable, it could run smoothly and successfully in my local windows PC with 32G memory, but my linux server with 8G memory failed and ran out of memory and no exception throw.

@larryzeng Does the problem occurs with a simple document created like this?

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Hello world!");

Or the problem occurs with some specific document? If so please attach the problematic document here for testing. Also, please described the environment where the problem occurs: Linux distribution, java version etc.