Hi Team,
We are facing “Cannot access a disposed object. Object name: ‘Document’.” exception while converting images to PDF.
Please find below detailed exception
class com.aspose.pdf.internal.ms.System.l8l: Cannot access a disposed object.
Object name: ‘Document’.
com.aspose.pdf.ADocument.l0y(Unknown Source)
com.aspose.pdf.ADocument.lj(Unknown Source)
com.aspose.pdf.Resources.lf(Unknown Source)
com.aspose.pdf.Page.dispose(Unknown Source)
com.aspose.pdf.Page.close(Unknown Source)
com.stormed.common.utils.ImageUtils.imageFileToPdfAspose(ImageUtils.java:277)
com.stormed.common.utils.ImageUtils.imageMergeToPDF(ImageUtils.java:811)
com.stormed.common.utils.ImageUtils.convertImagesToPDF(ImageUtils.java:861)
com.stormed.production.ProductionMain.(ProductionMain.java:101)
com.stormed.production.common.ProductionBuilder.run(ProductionBuilder.java:25)
com.stormed.proxy.AppRunner.run(AppRunner.java:26)
com.stormed.proxy.ProxyMain.runApp(ProxyMain.java:352)
com.stormed.proxy.ProxyMain.lambda$main$0(ProxyMain.java:140)
co.elastic.apm.agent.concurrent.JavaConcurrent$CallableLambdaWrapper.call(JavaConcurrent.java:253)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:829)
at com.aspose.pdf.ADocument.l0y(Unknown Source)
at com.aspose.pdf.ADocument.lj(Unknown Source)
at com.aspose.pdf.Resources.lf(Unknown Source)
at com.aspose.pdf.Page.dispose(Unknown Source)
at com.aspose.pdf.Page.close(Unknown Source)
at com.stormed.common.utils.ImageUtils.imageFileToPdfAspose(ImageUtils.java:277)
at com.stormed.common.utils.ImageUtils.imageMergeToPDF(ImageUtils.java:811)
at com.stormed.common.utils.ImageUtils.convertImagesToPDF(ImageUtils.java:861)
at com.stormed.production.ProductionMain.(ProductionMain.java:101)
at com.stormed.production.common.ProductionBuilder.run(ProductionBuilder.java:25)
at com.stormed.proxy.AppRunner.run(AppRunner.java:26)
at com.stormed.proxy.ProxyMain.runApp(ProxyMain.java:352)
at com.stormed.proxy.ProxyMain.lambda$main$0(ProxyMain.java:140)
at co.elastic.apm.agent.concurrent.JavaConcurrent$CallableLambdaWrapper.call(JavaConcurrent.java:253)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Please find the steps below and enclosed attachment.
Fetching all the documents to merge using below statement.
for (String imageFilePath : singlePageFilePathList) { // singlePageFilePathList will have documents path list
Reading each image using the statement.
java.awt.image.BufferedImage image = ImageIO.read(new File(inputFilePath));
Create Document object save document to output path
Document pdfDocument = new Document();
com.aspose.pdf.Image image1 = new com.aspose.pdf.Image();
image1.setBufferedImage(image);
page.getParagraphs().add(image1);
Using below statement to merge all the files.
String pdfFilePath = imageFilePath.substring(0, imageFilePath.lastIndexOf(’.’)) + “.pdf”;
List pdfFileList = new ArrayList<>();
pdfFileList.add(pdfFilePath);
new com.aspose.pdf.facades.PdfFileEditor().concatenate(pdfFileList.toArray(new String[0]), outFilePath);
Hello, @ashokreddyd!
As I can see the problem is in Aspose.PDF for Java, not in Aspose.Imaging for Java.
I can redirect you to the appropriate forum branch.
Would you kindly share the complete sample code snippet that we can use to replicate the similar issue in our environment? Also, please make sure to test the scenario with 23.4 version of the API before sharing the code snippet. We will further proceed to assist you accordingly.
I am continuing the conversation that @ashokreddyd started about this issue. Thanks for the assistance so far. I have followed your suggestion and upgraded our Aspose version to 23.4 and ran the same test again. For this particular issue, I am still getting the “Cannot access a disposed object. Object name: ‘Document’” error.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFJAVA-42790
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
You can check the ticket status at the bottom of this thread. Along with that, we will also keep you posted with the status of ticket progress via this forum thread.
Since the ticket was logged recently, it is pending for analysis. We will investigate it on a first come first serve basis and as soon as we have some updates in this regard, we will inform you. Please spare us some time.
We are afraid that the investigation could not be completed due to other issues in the queue. Nevertheless, we will surely inform you once we make some progress towards ticket resolution. Please spare us some time.