為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

Does the built-in PDF viewer support night mode? And is there a URL parameter for setting this when embedded in a web page?

  • 5 回覆
  • 1 有這個問題
  • 1 次檢視
  • 最近回覆由 JeffJepp

more options

I am embedding a PDF in an iframe like this:

           <iframe id="pdf_frame"></iframe>

I load the image using this Javascript:

       let frame = document.getElementById("pdf_frame");
       frame.src = pdfUrl;  /* URL of the PDF */

At night, my web page will be in a night mode (with a black background). I'd like to launch the embedded PDF viewer in night mode as well. Are there URL parameters to do this? Does the built-in viewer even support a night mode? I know that Acrobat supports a night mode.

I am embedding a PDF in an iframe like this: <div id="viewer_pane"> <iframe id="pdf_frame"></iframe> </div> I load the image using this Javascript: let frame = document.getElementById("pdf_frame"); frame.src = pdfUrl; /* URL of the PDF */ At night, my web page will be in a night mode (with a black background). I'd like to launch the embedded PDF viewer in night mode as well. Are there URL parameters to do this? Does the built-in viewer even support a night mode? I know that Acrobat supports a night mode.

所有回覆 (5)

more options

Hi JeffJepp, the built-in viewer has a dark toolbar and background (around the PDF) all the time. What would you want it to do differently?

By the way, development on the viewer is done via the following site -- this is the list of open issues:

https://github.com/mozilla/pdf.js/issues

more options

I probably wasn't clear. The PDFs I am displaying have a white background, while my web page has a black background. I want the PDFs to display with a black background to match my app.

I don't have control over the PDF generation, so they can't be produced with a black background in the first place.

I'm pretty sure Adobe Acrobat has a 'night mode' option, but I don't know if it can be set with a URL parameter. I'm hoping the built-in PDF viewer in Firefox has this capability too. And I'm hoping I can set it with a URL parameter.

more options

This page documents the current URL parameters: https://github.com/mozilla/pdf.js/wiki/Viewer-options

Looks like a Night Mode is a pending request and not yet available: https://github.com/mozilla/pdf.js/issues/2071

Here's a thought for now:

The viewer is available as a webapp* so in theory you could install that on your site, and point your iframe to the view, loading the PDF into it. All you would need to do in the viewer CSS is add this to invert the color scheme:

#viewer .page {
	filter: invert(1);
}

If you needed to create a URL parameter for that, more coding obviously would be involved...

* See: https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website

Perhaps that's not best for other browsers whose viewers have a native night mode and you'll need to "sniff"? If you try it, let us know how it goes.

more options

Thank you jscher. I will look into this.

more options

A little more info... it looks like the built-in Firefox PDF viewer supports themes. One is a "Dark Theme', that looks promising. If I can figure out how to set the theme with URL parameters, I think I'm there.