question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing text selection / highlight colors

See original GitHub issue

Hi, I’m using a slightly modified version of NightPDF to read PDFs. I read with complete inversion, so white text is displayed on a black background. However, I can hardly see the text highlight colors at all, especially when I use the find feature. I also have a color-deficiency, and this may be part of the problem.

Here are the default colors:

Normal Selection: Screen Shot 2021-05-07 at 4 07 11 PM

Find:

Screen Shot 2021-05-07 at 4 07 36 PM

I can hardly see these, and would like to make it a strong yellow or blue (FFFF00 or 0000FF).

NightPDF applies a filter that changes colors on the page. This can be seen in this js file at line 444. I just set inversion to 100% and leave all other settings at 0/default.

In order to try changing the highlight or find color, I tried to add this to the css:

   const highlightStyle = "\n.textLayer .highlight {\n" +
        "        background-color: rgba(0, 0, 0, 1);\n" +
        "      }\n" +
        ".textLayer .highlight.selected {\n" +
        "  background-color: rgba(0, 0, 0, 1);\n" +
        "}" +
        ".textLayer ::selection {\n" +
        "  background: rgba(0, 0, 0, 1);\n" +
        "}"

This is then added to the iFrames css. I used text_layer_builder.css to try to find find the right css. The reason I made the highlights all black was because I was trying to get it to show up as white (just for testing purposes) on the black background. Then, iI would try to ge it to the right color.

So my expectation with the above css was to see a white highlight on the black background. However, the highlight is grey:

Normal highlight: Screen Shot 2021-05-07 at 4 40 14 PM

Find: Screen Shot 2021-05-07 at 4 40 32 PM

In addition, I tried turning off the inversion filter in NightPDF (and thus expected a black highlight), but it was still grey:

Normal highlight Screen Shot 2021-05-07 at 4 41 26 PM

Find highlight Screen Shot 2021-05-07 at 4 41 43 PM

So, my one question here is really how can I have the direct control over the text selection/highlight/find color

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Snuffleupaguscommented, May 7, 2021

I’m using a slightly modified version of NightPDF to read PDFs.

Please note that that’s a different project, which is not connected to the PDF.js project, and as such we unfortunately cannot really provide (much) help/support for that here.

In addition, I tried turning off the inversion filter in NightPDF (and thus expected a black highlight), but it was still grey:

Perhaps this is what you’re looking for? https://github.com/mozilla/pdf.js/blob/a2652bafd91db17ad30a70bb1be703666efdea49/web/text_layer_builder.css#L23

(Please note that the general problem of inverting document colours is tracked in issue #2071.)


For future reference: When opening an issue, please provide all of the information requested in https://github.com/mozilla/pdf.js/blob/master/.github/ISSUE_TEMPLATE.md such that the issue becomes easily actionable/valid.

0reactions
mgroth0commented, May 7, 2021

Understood! Thank you for all the information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Highlighted Text Color in Windows 10
To Change Highlighted Text Color in Windows 10, · Open the Registry Editor app. · Go to the following Registry key. · See...
Read more >
How To Change Text Selection Color with CSS - W3Schools
Learn how to override the default text selection color with CSS. Text Selection Color. Select the following text: Default text selection color.
Read more >
How To Change The Selection Color When Highlighting Text ...
By default, the color used when you highlight text on a website is blue. Not only can you change the color, you can...
Read more >
I want to change the color of the highlighting when selecting text
Hi, There's not currently a way to change this in the Windows settings. There are colour filters you can apply in the settings...
Read more >
Change Background Color of selected or highlighted Text in ...
Change the Background Color of highlighted Text in Windows 11/10 ... To change the Highlight Color, open Registry Editor by going to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found