Hi,
When I try to encrypt a pdf document from different threads, it works only the first time, all next times, it fails with a nullpointerexception. Code to reproduce:
import com.aspose.pdf.CryptoAlgorithm;
import com.aspose.pdf.Document;
import java.io.IOException;
public class SetPermissions {
public static void main(String[] args) throws IOException, InterruptedException {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println(“Thread 1 started”);
createPdf(1);
System.out.println(“Thread 1 done”);
} catch (Exception ex) {
System.err.println("Thread 1: " + ex.getMessage());
ex.printStackTrace();
}
}
});
t1.start();
t1.join();
new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println(“Thread 2 started”);
createPdf(2);
System.out.println(“Thread 2 done”);
} catch (Exception ex) {
System.err.println("Thread 2: " + ex.getMessage());
ex.printStackTrace();
}
}
}).start();
}
private static void createPdf(int threadId) {
Document doc = new Document(“LoremIpsum.pdf”);
doc.encrypt(“user”, “owner”, 0, CryptoAlgorithm.RC4x128);
doc.save(“test_thread_” + threadId + “.pdf”);
}
}
output:
Thread 1 started
Thread 1 done
Thread 2 started
Thread 2: null
java.lang.NullPointerException
at com.aspose.pdf.ADocument.endOperation(Unknown Source)
at com.aspose.pdf.ADocument.encrypt(Unknown Source)
at com.aspose.pdf.Document.encrypt(Unknown Source)
at com.aspose.pdf.ADocument.encrypt(Unknown Source)
at com.aspose.pdf.Document.encrypt(Unknown Source)
at test.aspose.pdf.SetPermissions.createPdf(SetPermissions.java:48)
at test.aspose.pdf.SetPermissions.access$000(SetPermissions.java:9)
at test.aspose.pdf.SetPermissions$2.run(SetPermissions.java:36)
at java.lang.Thread.run(Thread.java:744)
Is there a way to work around this?
Best regards,
Steven.