Deleting non-visible layers #1010
Unanswered
erand96
asked this question in
Looking for help
Replies: 2 comments 3 replies
-
Oha, that's an interesting one! I only have a rough idea in my head, let me sketch it:
This should work ... 4 0 obj
<<
/Type /OCG
/Name (ocg1) % modify to "/Name (ocg1.fitz00001)"
...
>>
endobj This must happen as a modification in the source PDF! Before the copy. Which is no harm as long as the source PDF is not saved. |
Beta Was this translation helpful? Give feedback.
3 replies
-
Roughly should work like this: # doc = target PDF
for xref in range(1, doc.xref_length()): # loop through all object of target PDF
if not "/Type/OCG" in doc.xref_object(xref, compressed=True):
continue
_, name = doc.xref_get_key(xref, "Name")
name = name[1:-1] # remove the brackets
pos = name.find(".fitz") # check if OCG fro some source
if pos < 0:
continue ## not for us
old_name = name[:pos]
ocg_key = name[pos+1:]
ocg_state = ocg_states[ocg_key]
doc.xref_set_key(xref, "Name", old_name) # change back to old name
# now put the xref into /OCProperties arrays as dicussed in pre post |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I'm working on a project to convert ~1,000 PDF portfolios into normal PDFs with multiple pages. My process is:
The rest of my code is complete except for one error I continue to encounter. Some of the portfolio-attached PDFs have non-visible layers. When this PDF is extracted, the layers retain their invisibility, but when it is merged/attached into a multi-page PDF, all layers become visible.
I have messed around in PyMuPDF and found that using
doc1.insert_pdf(doc2)
allows me to retain the layer visibility on doc1, but makes all layers visible on doc2.Is there a different way to use PyMuPDF to ensure these layers remain invisible while merging/attaching multiple PDFs? Otherwise, can all invisible layers be deleted or have all images/content removed from them?
Thank you in advance for any help/ideas
Beta Was this translation helpful? Give feedback.
All reactions