-
-
Notifications
You must be signed in to change notification settings - Fork 959
Add support for optional content configuration #1996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hey! Excellent idea. Couple of questions:
|
…cument components, removing them from page props
Hi wojtekmaj, good point, since optional content groups are created by the I have added positive and negative render tests for the page with optionalContentConfig and tests for the document. |
a5dac89
to
30d9456
Compare
This is a work of art 🤩 I have one final concern that I think we should address to make this feature really useful. How we could trigger layer visibility change? Currently, even if you set the value, without forcing the entire document to reload by e.g. changing component keys, the layer visibility will remain unchanged. If this can be easily solved (I looked through PDF.js source quickly and didn't find it), then cool, if not - perhaps we should think about a wrapper exposing some methods from optionalContentConfig and calling additional methods instead. |
Hmm pdf.js uses this function in their viewer, but they change the configuration directly and trigger the new rendering via their own event bus. So this solution is not suitable for our situation. Any idea how to best approach building a wrapper for this? My current idea would be a RefObject, wrapping the configurations functionality. Initialized in the document while loading the document (similar to the link service). which is then passed to the page and can be used by the page via onStateChange/onVisibilityChange callback and from outside via a Document ref. This way we would not even have the need to load and pass the configuration from outside, as it could be loaded with the document. |
Check out #2004. I think we can somehow make it work :) |
Hmmm, doesn't look like this changes much, just adding EventBus doesn't magically cause the PDF to rerender, but it's not surprising. I guess another approach would be to expose optionalContentConfig using our own wrapper that gets the entire config and allows to set it, in a more React-y way. |
…cument and Page components, replacing optionalContentConfig usage. Update tests accordingly.
…essages. Improve readability in OptionalContentService and related components.
Okay, I have created a first design for the OptionalContentConfig wrapper (OptionalContentService). The rerender is now triggered by the Canvas Component, which is attached to a listener and the page test also covers the rerendering after layer visibility change. What do you think? :) |
# Conflicts: # packages/react-pdf/src/Document.spec.tsx # packages/react-pdf/src/Document.tsx # packages/react-pdf/src/shared/types.ts
# Conflicts: # packages/react-pdf/src/Document.spec.tsx # packages/react-pdf/src/Page.spec.tsx
This is a proposal for the implementation of optional content groups (PDF layers: https://helpx.adobe.com/acrobat/using/pdf-layers.html).
The configuration can be created by
PDFDocumentProxy.getOptionalContentConfig
and will then be used byPDFPageProxy.render
.pdf.js reference -> mozilla/pdf.js#269 (comment)