Cannot access a disposed object. Object name: 'Document'

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)

We are using below versions of aspose.

    [group: 'com.aspose', name: 'aspose-pdf', version: '23.1'],
    [group: 'com.aspose', name: 'aspose-imaging', version: '22.7']

@ashokreddyd, Could you provide sample code and source images ?

@stanislav.popov Thank you for your quick response.

Please find the steps below and enclosed attachment.

  1. Fetching all the documents to merge using below statement.
    for (String imageFilePath : singlePageFilePathList) { // singlePageFilePathList will have documents path list
  2. Reading each image using the statement.
    java.awt.image.BufferedImage image = ImageIO.read(new File(inputFilePath));
  3. 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);
  4. 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);

tiff_merge_to_pdf.7z (1.4 MB)

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.

@evgeniy.sidenko

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.

Hi Aspose Team,

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.

Here is the detailed error that I am getting:

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:397) com.stormed.common.utils.ImageUtils.imageMergeToPDF(ImageUtils.java:931) com.stormed.common.utils.ImageUtils.convertImagesToPDF(ImageUtils.java:981) com.stormed.production.ProductionMain.<init>(ProductionMain.java:102) com.stormed.production.common.ProductionBuilder.run(ProductionBuilder.java:25) com.stormed.proxy.AppRunner.run(AppRunner.java:25) com.stormed.proxy.ProxyMain.runApp(ProxyMain.java:353) com.stormed.proxy.ProxyMain.lambda$main$0(ProxyMain.java:141) 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:1136) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) java.base/java.lang.Thread.run(Thread.java:833)

Aspose.PDF now at 23.4

[group: 'com.aspose', name: 'aspose-pdf', version: '23.4']

Can you please advise next steps to remediate this issue?
I’m also happy to get on a call to discuss as well if that is easier.

@ashokreddyd

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.

Thank you so much for escalating the issue.

Is there any way I can view this ticket? If not, that’s fine and you can keep us updated on this post.

I’ll ask my manager to see if we need to take advantage of the Paid Support Services.

@vcaspose

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.

@asad.ali

Ok, great!
Thank you! Please keep me updated. Let me know if you need anything from me.

@vcaspose

Sure, we will let you know in case we need some information from your side during ticket investigation.

Hi @asad.ali

Hope you are doing well. Any updates from your dev team on this issue?

Thank you

@vcaspose

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 sorry for the inconvenience.

Thank you @asad.ali

Let us know when you have an update.

@vcaspose

Sure, we will inform you.

@asad.ali has your team been able to look into this issue?

@aweech

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.

We are sorry for the inconvenience.