Blog · Under the hood
How Dark Mode ConversionActually Works
Most tools repaint your PDF pixel by pixel. PDF Dark rewrites the file's own color instructions — and falls back gracefully when it can't.
A PDF is a program, not a picture
Every PDF page is a list of drawing instructions: “set the fill color to black, write this text at these coordinates, place this image in this rectangle.” There are two very different ways to make that page dark.
Way 1 — repaint the pixels
- Render the page to a bitmap, flip every pixel
- Fast to build, works on anything
- But: photos become negatives, text turns into pixels (blurry at zoom, no selection), files bloat
- This is what nearly every converter does
Way 2 — rewrite the instructions
- Find every “set color” instruction in the file and swap its values into the dark theme
- Text stays real text: selectable, searchable, sharp at any zoom
- Images aren't touched unless you want them to be
- File size stays close to the original
PDF Dark uses Way 2 wherever the file allows it — and Way 1, upgraded, everywhere else.
Vector recoloring, with hue preserved
Swapping black↔white is easy. The interesting question is what to do with everything in between.
Near-grayscale colors follow the theme
White backgrounds become your theme color (Midnight's deep blue, OLED's pure black…), black text becomes near-white, grays land proportionally in between. This is the classic luminance flip.
Colored text keeps its hue
A dark-blue heading doesn't turn muddy gray — it becomes lightblue. Red warnings stay recognizably red, links stay blue. Technically: chromatic colors get their lightness flipped while hue and saturation survive, so the author's color semantics carry into the dark theme.
Bonus: everything else survives too
Because the file is edited rather than re-rendered, bookmarks, internal links, and the document outline all survive conversion untouched.
Images: found by structure, judged by content
No computer vision needed — the PDF declares where every image sits. What to do with each one is the real decision.
Exact positions from the file itself
Every image placement in a PDF comes with a transform matrix. Replaying the page's instruction list gives pixel-exact bounding boxes — including circular crops (think resume avatars), which are restored through their round frame so no light corners leak back onto the dark page.
The Auto classifier
Each image is sampled for brightness and colorfulness, then gets one of three treatments: white colorless figures (screenshots, tables) are inverted so they blend into the page; photos are kept in original colors; bright colorful images get a gentle dimso they don't glare at night. The Images toggle in the toolbar can force all-Original or all-Invert instead.
Downloads get the native-resolution originals
Preserved images are re-embedded into the saved file from their original data at up to full native resolution — text inside figures stays crisp when you zoom, instead of inheriting screen-resolution blur.
The fallback chain: never ship a broken page
PDF color is a deep rabbit hole — spot colors, gradients, indexed palettes, tiling patterns. Rewriting those wrongly could corrupt a page, so every page passes a health check first.
Vector recolor — used when every color instruction on the page is fully understood (plain RGB, grayscale, CMYK). Most Word, Google Docs, LaTeX, and print-to-PDF files land here.
Raster fallback— if a page uses color machinery we can't safely rewrite (spot colors, gradients, patterns), just that page is rendered dark as a bitmap instead, with preserved images re-embedded at native resolution and an invisible text layer keeping search and copy alive. A wrong-looking gray page beats a corrupted one, every time.
Scanned pages — a scan is one big image, so there are no instructions to rewrite; the page is inverted uniformly (or left untouched in Original mode). Handwriting and old book scans normalize beautifully to the theme background.
The decision is per page, not per file — a report with one exotic chart page keeps vector text on the other forty-nine.
See it run on your own PDF
All of the above happens in your browser, in seconds
Drop a file on the home page and watch: vector text, preserved photos, and a theme of your choice — nothing uploaded anywhere.
Try PDF Dark →More from the PDF Dark blog
Different angles on the same converter — pick the post that matches your scenario. The drop zone is at the top of every page.
PDF Dark Mode in Chrome
PDF Dark Mode in Firefox
Convert PDF to Dark Mode
How to Darken a PDF
Darken a Scanned PDF Online
Invert PDF Colors, Keep Your Images
Under-the-hood FAQ
Which PDFs get the vector treatment, and which fall back?
Files exported from Word, Google Docs, LaTeX, browsers ('Print to PDF'), and most e-book pipelines declare their colors in plain RGB or grayscale — those recolor as vectors, keeping text selectable and razor-sharp. Design and print-shop files that use spot colors, gradients, color patterns, or indexed palettes fall back to the raster path for that page. Scanned pages are images by nature and always take the raster path.
Why not just invert every pixel? It sounds simpler.
It is simpler — and it's what most tools do. But pixel inversion turns photos into film negatives, locks text at screen resolution (blurry when zoomed), destroys text selection, and bloats file size. Rewriting the PDF's own color instructions avoids all four problems at once.
How do you find the images on a page?
The PDF's drawing instructions are read directly: every image placement is declared in the file along with its transform matrix, so we compute each image's exact position — including whether it's cropped by a circular frame. No computer vision involved; the file itself tells us where its images are.
What does the Auto image mode actually measure?
Each image is downsampled and sampled for average brightness and colorfulness. Bright + colorless → treated as a document-style figure and inverted with the page. Mid or dark brightness → treated as a photo and kept original. Bright + colorful → gently dimmed so it doesn't glare. You can override with Original or Invert at any time.
If a page falls back to raster, do I lose text search?
No. Raster pages get an invisible text layer — the same technique OCR'd scans use. The text content and positions come straight from the PDF, so search, selection, and copy still work; only the visual sharpness is capped at render resolution for that page.
Does any of this require uploading my PDF?
No. Parsing, recoloring, image detection, and reassembly all run inside your browser (pdf.js for reading, a Web Worker for pixel work, pdf-lib for writing). The file never leaves your device.