I tried adding a Dark Reader mode to Okular. Here's where I got stuck

I was experimenting with adding a Dark Reader–style mode to Okular for PDF documents.

The goal was to darken the page while keeping embedded images untouched. The existing accessibility color modes recolor every pixel, so photos, screenshots, and other raster images also get inverted or recolored, which isn’t ideal.

My first implementation worked by post-processing the rendered page. Since Poppler gives you a flattened bitmap through renderToImage(), I used a simple chroma heuristic: recolor near-grayscale pixels (assuming they’re text/background) and leave colorful pixels alone. It actually worked reasonably well, but grayscale or muted-color images could still get recolored, which is an unavoidable limitation of that approach.

So I tried to be more hacky.

Instead of modifying the final rasterized image, I tried working inside Poppler before everything gets flattened. From what I understood, poppler-qt6 only exposes Page::renderToImage(), but Poppler’s core library has the OutputDev API (SplashOutputDev, CairoOutputDev, etc.), where the renderer still knows whether it’s drawing text, vector graphics, or embedded images. My idea was to hook in there so I could recolor only text/vector content while leaving raster images completely untouched.

Unfortunately, I couldn’t get it working the way I wanted. The result was basically just a grayscale/black-and-white rendering instead of the Dark Reader–style effect I was aiming for.

Has anyone here worked with Poppler’s OutputDev API or implemented something similar? Is this the right direction, or is there a better approach for separating text/vector content from images during rendering?

The code is in : github(dot)com/justbipin/okular, please have a look

Note: I’m not familiar with the C++ ecosystem at all, so I leaned pretty heavily on Zed Editor’s free AI to help build the feature. I eventually ran out of free usage though. :crying_cat: Any guidance from people who know Poppler or Okular’s rendering pipeline would be greatly appreciated.

invert lightness and invert colors work differently

the invert lightness may be more what you are looking for.

there are also other PDF viewers that offer a dark mode such as NightPDF

i have tried all of them,invert color, invert lightness and even invert luma ( I liked invert luma more) , but they invert the image too, i dont’ want that,

look at the attached image to see how “dark reader” works

yes, everything else is inverted, it’s just the images that remain the same, and i think it’s awesome, though i have yet to add features to change the background color to a custom color, that will also come. but i think i like how my implementation works. Also, i found that i works, but i just have to zoom in or zoom out to rerender the page, i don’t know why

good luck with your mods to okular then… perhaps you can get it to work like these others and contribute to its growth

but in the mean time, i would rely on one of these other packages to meet your needs

Update: it’s working !!!. i am adding more features like custom background color for dark mode and a keyboard shortcut too, can’t think of a keyboard shortcut to keep tho. please check it out on https://github.com/justbipin/okular