Hello,
we were always using the Aspose Pdf 3.0.1 for Java and the following program was working for us:
import aspose.pdf.Pdf;
import aspose.pdf.Section;
import aspose.pdf.Security;
import aspose.pdf.Text;
public class Test {
public static void main (String args[]) throws Exception {
Pdf pdf = new Pdf();
Security pdfSecurity = new Security();
pdfSecurity.setUserPassword(“123”);
pdf.setSecurity(pdfSecurity);
Section section = pdf.getSections().add();
section.getParagraphs().add(new Text(“bolabla”));
pdf.save(“d:\temp\1\2.pdf”);
}
}
Recently we have updated to V. 9.3.0. But now PDF files generated by this simple program can not be opened with Acrobat Reader anymore. Acrobat asks for the password, you type “123”, and it says “The password is wrong”.
I have tried different versions but this functionality seems to get broken on the version 4.3.0, as with the 4.2.1 it is still working.
Am I doing something wrong? Or what? Please explain.
Igor
Hi Igor,
Thanks for your inquiry. I have tested the scenario with Aspose.Pdf for Java 9.5.0 and managed to replicate the encryption issue in aspose.pdf package. We have logged a ticket PDFNEWJAVA-34506 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.
Moreover, we will suggest you to use new DOM approach, com.apose.pdf package. It is more effecient and improved. Please check sample code snippet for encryption. Hopefully it will help you to accomplish the task.
//open document
com.aspose.pdf.Document document = new com.aspose.pdf.Document();
//add a new page in document
document.getPages().add();
//encrypt PDF
document.encrypt("user", "owner", 0, com.aspose.pdf.CryptoAlgorithm.AESx256);
// save updated PDF
document.save(myDir + "Encrypted_output.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
The issues you have found earlier (filed as PDFNEWJAVA-34506) have been fixed in Aspose.Pdf for Java 10.1.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.