Partial support for OCG (layers) added to PDFium

36 views
Skip to first unread message

Jason Alexander

unread,
Aug 31, 2026, 6:53:53 PM (3 days ago) Aug 31
to pdfium

Hi there,

With Claude Code's help, I've added partial support for OCG to pdfium. You can now toggle layers on and off, create new layers, and add annotations to layers.

Here's the GitHub link:

https://github.com/jmckalex/pdfium-ocg

As a proof of concept regarding its usefulness, here's a link to a page with an enhanced version of EmbedPDF. If you click on the left sidebar, you will see a new layers button added. That shows the layer structure, with the ability to add new layers and groups.

https://jmckalex.github.io/pdfium-ocg/

Happy to contribute this code, if you'd find it useful!

Best wishes,

Jason Alexander
jmck...@gmail.com

geisserml

unread,
Sep 1, 2026, 4:54:33 AM (2 days ago) Sep 1
to pdfium
Yes, OCG support is indeed missing from the public API. I seem to remember having filed a feature request years ago.
So it would be very interesting to my end. Only I don't think it's a good idea to use AI to write code... :/

Jason Alexander

unread,
Sep 1, 2026, 5:26:19 AM (2 days ago) Sep 1
to pdfium
Do try out the demo code at https://jmckalex.github.io/pdfium-ocg/ — it works perfectly and any OCG layers added to a PDF are recognised by Adobe Acrobat.

I appreciate the concern about using AI to write code, but I tend towards consequentialism on this point. OCG support has been missing for years, but it only took me a couple of hours to add it with Claude Fable.  A person can't use merely possible code.

K. Moon

unread,
Sep 1, 2026, 5:33:50 AM (2 days ago) Sep 1
to Jason Alexander, pdfium
PDFium contributors must follow this policy: https://pdfium.googlesource.com/pdfium/+/HEAD/CONTRIBUTING.md

PDFium follows the Chromium AI policy: https://chromium.googlesource.com/chromium/src/+/main/agents/ai_policy.md

Regardless of how the code is written, PDFium won't consider or even look at code that hasn't been submitted through the formal contributor process.

--
You received this message because you are subscribed to the Google Groups "pdfium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pdfium/b6fd0d17-e257-4661-b836-8c0d7af671cbn%40googlegroups.com.

geisserml

unread,
Sep 1, 2026, 7:02:27 AM (2 days ago) Sep 1
to pdfium
Thanks for pointing out what the policy is. The bit that AI code must be fully understood by the human submitter is essential.

> [...] I tend towards consequentialism on this point. OCG support has been missing for years, but it only took me a couple of hours to add it with Claude Fable.  A person can't use merely possible code.

Yes, and that's what I find concerning. Sounds like a very short-term attitude to me. Can such rapidity result in high-quality, well-understood code? I doubt it. It's like a prefab vs. a solid brick wall.
I mean, I can't and don't want to give judgement about these patches since pdfium's internals are (mostly) a black box to me – I only use the public C API through an FFI interface.
But what I can say is that any and all AI-assisted issues/PRs I have received at the (python c extension) project I maintain have been garbage, especially those produced by Claude Code.
Even when using an AI draft + manual editing, I found the results were generally poorer and much more prone to false assumptions than if the author had written all code on their own.
Higher-quality models might exist or become available in the future, but so far my experience with AI code has been very negative. Just so you understand where my POV comes from.
Reply all
Reply to author
Forward
0 new messages