Decrypt/Encrypt results in corrupted document or error

Hello,

In our company we have a web applicattion which receives PDF documents as input, works with the documents by stamping them and then encrypts the document and returns to user. We use Aspose.PDF 9.7.0 (latest version at this moment).

This results in an error while trying to encrypt the PDF, even if the PDF has not been decrypted (because we check if it is encrypted):
class com.aspose.pdf.internal.p235.z73: Object not found —> java.lang.IllegalStateException: Reference table is not repaired
— End of inner exception stack trace —
com.aspose.pdf.internal.p424.z11.m1(Unknown Source)
com.aspose.pdf.ADocument.encrypt(Unknown Source)
com.aspose.pdf.Document.encrypt(Unknown Source)
idiada.zeus.services.documents.impl.AdvancedFileOperationsImpl.restrictPdf(AdvancedFileOperationsImpl.java:1043)




Decryption:
private String writePdfUnprotecting(InputStream inStream, String docName, String outFolder) throws SystemException {

com.aspose.pdf.Document document = new com.aspose.pdf.Document(inStream);
try /Decrypt if document is encrypted/
{
if(document.isEncrypted()){
document.decrypt();
}
document.save(outFolder + docName);
}
finally { if (document != null) document.close(); }

} catch (Exception e) {
log.error(e);
throw new SystemException(e, ERROR_WRITTING_DOC, e.getMessage());
}
return docName;
}


Encryption:
public void restrictPdf(String inputName, String outputName, String inFolder, String outFolder) throws SystemException {
try {
com.aspose.pdf.Document document = new com.aspose.pdf.Document(inFolder + inputName);
try /JAVA: was using/
{
document.encrypt("", “”, Permissions.PrintDocument, CryptoAlgorithm.AESx128, false);
document.save(outFolder + outputName);
}
finally { if (document != null) document.dispose(); }

} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SystemException(“exception.service.errorrestrictingdoc”, e.getMessage());
}
}

PD: I also attached a sample document we use for testing. It is a simple PDF document created from MS Word.

Hi Cristina,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for Java 9.7.0 in Eclipse Juno project with JDK 1.7 running over Windows 7 (x64) and I am unable to notice any problem (tested both Encryption and Decryption) scenario. Can you please share some details regarding your working environment. We are sorry for this inconvenience.

Hello,

I prepared a Junit Test for testing this case so you can reproduce yourself the problem.

private String writePdfUnprotecting(InputStream inStream, String docName, String outFolder) throws IOException {
com.aspose.pdf.Document document = new com.aspose.pdf.Document(inStream);
try /* Decrypt if document is encrypted /
{
if (document.isEncrypted()) {
document.decrypt();
}
document.save(outFolder + docName);
inStream.close();

} finally {
if (document != null) document.close();
}

return docName;
}

private void restrictPdf(String inputName, String outputName, String inFolder, String outFolder) {
com.aspose.pdf.Document document = new com.aspose.pdf.Document(inFolder + inputName);
try /
JAVA: was using */
{
document.encrypt("", “”, Permissions.PrintDocument, CryptoAlgorithm.AESx128, false);
document.save(outFolder + outputName);
} finally {
if (document != null) document.dispose();
}
}

@Test
public void decryptEncryptPDF() throws IOException{
java.io.File testPDF = new File(this.getClass().getResource("/docs/test.pdf").getFile());

writePdfUnprotecting(new FileInputStream(testPDF), “test_decrypted.pdf”, testPDF.getParent());
File file1 = new File(testPDF.getParent()+“test_decrypted.pdf”);
Assert.assertTrue(file1.exists());

restrictPdf(“test_decrypted.pdf”, “test_encrypted.pdf”, testPDF.getParent(), testPDF.getParent());

File file2 = new File(testPDF.getParent()+“test_encrypted.pdf”);
Assert.assertTrue(file1.delete());
Assert.assertTrue(file2.delete());
}

Our environment is Eclipse Kepler, JDK 1.7 and Windows 7 x64. We also test this case with the free (and outdated) library iText and works fine…so please run this code with the PDF I attatched previously and check it again.

The error I am gettinng getting is the one described in the first post: java.lang.IllegalStateException: Reference table is not repaired

Please give us a response as soon as possible.

Regards.

Hi Cristina,


Thanks for sharing the details.

We are working on testing the scenario in our environment and will get back to you soon.

Hi Nayyer,

Have you been able to execute the test? Please give us an answer as soon as posible.

Regards

Hi Cristina,


Thanks for your patience and sorry for the delayed response.

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-34610. We will
investigate this issue in details and will keep you updated on the status of a
correction. <o:p></o:p>

We apologize for your inconvenience.

Any news about this issue? It have passed almost a month since the latest information.

Regards.

Hi Cristina,


Thanks for your inquiry. I am afraid your issue is still not resolved, it is pending for investigation due to the other issues already under investigation and resolution. We have requested our development team to share an ETA at their earliest. We will update you as soon as we get a feedback.

Thanks for your patience and cooperation.

Best regards.

The issues you have found earlier (filed as PDFNEWJAVA-34610) have been fixed in Aspose.Pdf for Java 10.0.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.