Remove a layer

I need to remove a layer from a pdf using Aspose PDF java.
How can I do this.
I tryed but I got an error when I save the document :
Exception in thread “main” class Cannot access a disposed object.


Could you please share your sample PDF along with sample code snippet that you have tried. We will test the scenario in our environment and address it accordingly.

Sorry, I replayed by mail, now I see I should reply in this form
Here the file with the layer.
I tried to remove the layer using
I also tryed
page.setLayers(new ArrayList());.
With the same result.


We coudl not find any attachment with your post. Would you kindly make sure to upload the file using post editor.

I reported my code in the previous post.
I don’t know how to post my whole class.
Where the post editor is ?
How can I use it ?


We are asking for a sample PDF file, not the code. You can use upload button in the post editor to upload you sample file that you are using at your side. This would help us testing the scenario accordingly. uploadfile.png (7.0 KB)

R4.pdf (103.9 KB)
Here the file.

I investigated a little bit.
The document I sent You contains the layer and I see it from Acrobat Reader.
When I try to read it using page.getLayers() I get null.
The layer is on page 13.
Is it a bug ?


We were able to notice the same issue in our environment with Aspose.PDF for Java 20.7 and logged it as PDFJAVA-39606 in our issue tracking system. We will further check this case in detail and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFJAVA-39606) have been fixed in Aspose.PDF for Java 22.1.