Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.16k stars 680 forks source link

Is it possible to create Optional Content Group (OCG) with weasyprint? #1238

Open bolatuly opened 4 years ago

bolatuly commented 4 years ago

Is it possible to create Optional Content Group (OCG), collection of graphics that can be made visible or invisible dynamically, with weasyprint?

Chapter 8.11.2 in https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf

liZe commented 4 years ago

Hello!

No, it’s not possible (yet). But when we have our own PDF writer (you can follow #1232 if you want to get news about that), we’ll be able to add this feature.

hiaselhans commented 1 year ago

So, since #1770 is closed, i am joining here for discussion.

The reason i am looking into OCG support is that when converting SVG images, it would be really nice to preserve the document structure for later editing of the generated PDF.

I will try to get a deeper insight the next days. If you have useful resources for me, I'd be happy to have them at hand.

Thanks for the great lib!

liZe commented 1 year ago

I will try to get a deeper insight the next days. If you have useful resources for me, I'd be happy to have them at hand.

If you want to have a quick and dirty way to implement this, you can probably add some code here: https://github.com/Kozea/WeasyPrint/blob/d689454fd6acfaf64a41845894484b16049ee6c6/weasyprint/svg/__init__.py#L434

It should be possible to add the OCG and OCMD dictionaries when the tag is g, and it could be useful to get this code working if you’re interested, even if we don’t merge it as-is.

As explained in #1770, the real challenge here comes after the proof of concept. As we don’t want to add these groupes unconditionally, and as the use cases will be different depending on the users needs, we have to provide a clean API that can let users do what they want where they want. To be honest, I don’t know how/if it’s possible to do this, other than letting users monkey-patch the current functions (that are not officially public). But if anyone has an idea, it’s the place to discuss about this topic!