We are using Aspose.PDF for Java in our product (version 21.10). We occasionally see the following error when calling com.aspose.pdf.Page.getPageRect(false):
Value cannot be null.
Parameter name: trailerable
This is coming from a com.aspose.pdf.internal.ms.System.lk exception being thrown. I have not been able to find any information online about what this error means. Also, I’m not sure if this is an Aspose bug or if this is expected behavior. If it is expected behavior, I’m not sure why an internal exception is being thrown.
@atcollins06
Can you please try using the latest version of the API and see if error still persists? Also, does it occur with specific PDF files? Please share sample document with us along with minimal code to reproduce the issue so that we can further proceed accordingly if issue is still occurring with the latest version of the API.
Unfortunately, I don’t have ready access to the file since our app doesn’t currently save it if it fails to process. So, at the moment, I can’t reproduce it.
Is it expected that calling code should see a com.aspose.pdf.internal.ms.System.lk exception?
@atcollins06
Sorry for the delayed response. We are afraid that we cannot determine the issue without replicating the issue in our environment. For the purpose, we requested information in our previous message. If possible, could you please provide that so that we can further proceed accordingly.
Understood. As mentioned, I don’t currently have access to a file that is causing the issue. I will try see if we can make changes to our application so that we capture the file next time this issue occurs.
@atcollins06
Sure, please take your time to gather the information and let us know once you are able to share it. We will further proceed accordingly.
I was able to track this issue down a bit more. You can see the exception thrown with the following program (that mimics what our code is currently doing):
public static void main(String[] args) throws Exception {
try {
Document pdfDocument = new Document(new FileInputStream(args[0]));
File tempFile = File.createTempFile("aaa", ".pdf");
// com.aspose.pdf.internal.ms.System.lk exception thrown if these lines are uncommented. Otherwise, no issues are seen
// pdfDocument.getPages()
// .forEach(page -> page.setPageSize(page.getPageRect(false).getWidth(), page.getPageRect(false).getHeight()));
pdfDocument.save(new FileOutputStream(tempFile));
pdfDocument.close();
Document mergedDocument = new Document();
mergedDocument.getPages().add(new Document(new FileInputStream(tempFile)).getPages());
} catch (Exception e) {
// Error message is
// Value cannot be null.
// Parameter name: trailerable
System.out.println(e.getMessage());
}
}
and the attached PDF file
document.pdf (1.5 MB)
@atcollins06
We tested your code snippet with 24.12 version of the API and could not replicate or reproduce the exception you mentioned. Can you please try using 24.12 version and let us know if error still persists. Please note that we used same file that you have shared with us.
OK. It does appear that the problem goes away with the latest version. Need to work with my manager to get our license updated so that we can use the latest version in our product. Thanks for your help.
@atcollins06
Sure, please feel free to cerate a new topic in case you face any kind of issues.