Turn on/off lights

Dark mode for Firefox's built-in PDF viewer

Surprisingly, Firefox's PDF viewer does not have a native option to invert colors in PDF. Presently no extension exists which can do this job. Dark Reader does not work with PDF's. At around 8'O clock today, I decided to fix the problem once and for all with a simple Firefox extension.

After hunting on the web for about 30 minutes, I found this thread on Bugzilla. It turns out starting with Firefox 60, extensions are no longer allowed to interact with the native pdf viewer. Determined, I decided to locally modify the CSS rendered by Firefox's PDF viewer. The steps for the same are:

(Following is a fix I created by mixing Superuser - How can I override the CSS of a site in Firefox with userContent.css? with Reddit - Dark PDF Preview)

  1. Open Firefox and press to show the top menu, then click on
  2. Click the button beside the entry
  3. Create a folder named in the directory that opens
  4. In the folder, create a CSS file with the name
  5. Open the file and insert -
  6. #viewerContainer > #viewer > .page > .canvasWrapper > canvas {
        filter: grayscale(100%);
        filter: invert(100%);
    }
  7. On Firefox's URL bar, type .
  8. Search for and set it to .
  9. Restart Firefox and fire up a PDF file to see the change!

screenshot of Firefox rendering a PDF with dark background

Screenshot of Firefox rendering a PDF with dark background

Update (26/05/2020): As of Firefox 77.0b9, if you enable spreads (for side-by-side viewing), the style is not being rendered. However, changing the above selector path to fixes the issue. Specifically for spreads, the selector path has changed to . Thanks to the reddit user /u/BotOfWar for pointing out this change and it's fix. If you find any further issues/updates here is the reddit thread of this blogpost (archive.org).