Skip to content

How to change the background color of the document page in pdf.js #18

@sedimentation-fault

Description

@sedimentation-fault

Configuration

  • Web browser and its version:
    Pale Moon 32.4.0.1
  • Operating system and its version:
    Linux, 5.4.196-gentoo
  • PDF.js version: 2.3.240
  • Is a browser extension:
    Yes

Steps to reproduce the problem

  1. Open any PDF with white page background.
  2. Try to change the background color of the page

What is the expected behavior?

I would like to change the background color of the page (the PDF page, where the text of the PDF appears) from the usual white to something more eye-friendly.

What went wrong?

No matter what I try it seems impossible to change the page background color.
I use the Stylem extension to set my own CSS for PDFs. This is a Pale Moon specific extension, but it works like the Stylish extension for Firefox and uses the same CSSs. While all the following works and changes the colors of the toolbar, sidebar, links etc.

@-moz-document regexp(".*.pdf")
{
/* Viewer body area: dark side margins */
#viewer.pdfViewer {
	background-color: #EACCAF !important;
}

/* Viewer toolbar and elements */
#toolbarContainer > #toolbarViewer, 
#toolbarContainer > #toolbarViewer input,
#toolbarContainer > #toolbarViewer select,
#toolbarContainer > #toolbarViewer option,
#toolbarContainer > #toolbarViewer span,
#secondaryToolbar,
#secondaryToolbar > #secondaryToolbarButtonContainer button {
	color: #eee !important;
	background-color: #4992A7 !important;
}
  

#toolbarContainer > #toolbarViewer button::before,
#toolbarContainer > #toolbarViewer a::before,
#toolbarContainer > #toolbarViewer span::after,
#secondaryToolbar > #secondaryToolbarButtonContainer button::before {
	filter: invert(1) !important;
}
  

#toolbarContainer > #toolbarViewer button:hover,
#toolbarContainer > #toolbarViewer a:hover,
#sidebarContainer a:hover
{
	background-color: #EDA870 !important;
}

  
#sidebarContent {
    background-color: #4992A7 !important;
  }

} 

, none of the following has any effect:

.page, .canvasWrapper, .textLayer {
    background-color: #EACCAF !important;
  }
html body div#outerContainer.sidebarOpen div#mainContainer div#viewerContainer div#viewer.pdfViewer div.page div.textLayer {
   background-color: #EACCAF !important;
}

#viewerContainer > #viewer > .page > .canvasWrapper > canvas {
    background-color: #EACCAF !important;
}

It seems that pdf.js will use white, no matter what one sets for canvas, textLayer, or whatever CSS selector...

pdfjs-page-background-color

As you can see in the screenshot above, page background remains white.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions