Control the visibility of a story #3010
-
Is it possible to define visibility, i.e. set OCG/layer, for a story object? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
No, not directly as such, because the output of a story by definition is a sequence of rectangles, on one or more pages. However, you can use a story in |
Beta Was this translation helpful? Give feedback.
-
You can also use story.write_with_links. Then take the pages of your target PDF and insert those story pages via show_pdf_page. I am referring to a snippet like this: src = story.write_with_links(rect_callback, pagefn=page_callback, ...)
doc = fitz.open()
for srcpage in src:
page = doc.new_page(width=srcpage.rect.width, height=srcpage.rect.height)
page.show_pdf_page(page.rect, src, srcpage.number, oc=ocg_xref)
... Just a more or less generic example. |
Beta Was this translation helpful? Give feedback.
-
@Andreasox - does the above make sense? |
Beta Was this translation helpful? Give feedback.
-
Yes, thanks a lot. Then I now how we can handle this. |
Beta Was this translation helpful? Give feedback.
A Story is no PDF-relevant object at all.
In PDF, only certain objects can be subject to OC visibility control: images, Form XObjects, annotations and segments within a page's
/Contents
objects (to cover text and vector graphics).BTW a PDF page cannot be subject to OC either.
Story obviously is none of the above. More than anything else it is a HTML DOM plus a number of methods to achieve placement on rectangles. A Story even doesn't even know what a PDF is.
Its output producing methods
.place()
and.draw()
can be directed to a new PDF using the DocumentWriter class, at which point, the Story seizes to exist ... in a way.Only the output to a PDF which it has created in cooperation with …