Is there a way to delete an OCG layer from a PDF within Python?
I normally work with pymupdf but couldn't the functionality there. Is there any other library with this functionality?
Is there a way to delete an OCG layer from a PDF within Python?
I normally work with pymupdf but couldn't the functionality there. Is there any other library with this functionality?
Copyright © 2021 Jogjafile Inc.
disclaimer: I am the author of
borb
the library mentioned in this answer.borb
will turn any input PDF into a JSON-like data structure. If you know what to delete in the content-tree, you can simply remove that item from the dictionary as you would in a normal dictionary object.Reading the
Document
is easy:You need
document["XRef"]["Trailer"]["Root"]["OCGs"]
which will be aList
of layers. Remove whatever element(s) you want.If you then store the PDF, the layer will be gone.