react-pdf-highlighter icon indicating copy to clipboard operation
react-pdf-highlighter copied to clipboard

Change the Color of highlighter

Open mark7588 opened this issue 2 years ago • 6 comments

Is there any way to change the color of highlighter dynamically? I have been inspecting codes to apply to my project but I could not find any styling element that sets the color of the highlighter.

mark7588 avatar Mar 26 '22 16:03 mark7588

Check the "./src/style/" files there you'll find the css classes for ".textLayer ::selection" and ".Highlight_part", which sets the highlight color. During selection, and rendering the highlights

OscarBC avatar Mar 26 '22 19:03 OscarBC

Thanks for letting me know. I am little confused since I have those files in the node_module In the project, I imported this source code as node_module and integrate example_code file into my project folder. Does that mean I need to change style file in the node_module/react-pdf-highlighter?

mark7588 avatar Mar 27 '22 21:03 mark7588

You should define that style in your project, if you implemented the example_code you should have something like the /styles/App.css, there should be a good place to override the default style. In whatever class you implemented the react-pdf-highlighter.

I wouldn’t recommend you to make any changes inside node_modules since those files are managed by npm and your changes can easily be lost.

OscarBC avatar Mar 28 '22 13:03 OscarBC

I've tried with different approaches but they all failed... The followings are what I tried:

  1. Change the CSS style code in node_modules: does not have any effect on color
  2. Import components from node_module and import components from my own local folder --> same result as 1
  3. Apply style to the imported Highlight component by adding specific className to the component --> same result as 1 Thanks so much for helping me!

mark7588 avatar Apr 02 '22 18:04 mark7588

you could probably do what I did, and say, make a separate folder for the library, clone the project there and install it to set it up. Not exactly the cleanest solution, but if nothing else works this would. You could then make any changes you require. How viable this is depends on your use case, but if nothing else works, this would.

sarcXD avatar Apr 07 '22 09:04 sarcXD

There is no need for cloning the project. You just need to copy the below files to your project, you will find these files in your node modules. Screenshot 2022-07-27 at 4 09 12 PM import these files where you are using the PdfHighlighter component like this import "./style/AreaHighlight.css"; import "./style/Highlight.css"; import "./style/Highlighter.css" import "./style/MouseSelection.css"; import "./style/pdf_viewer.css"; import "./style/Tip.css";

Now you can edit these files to override the css of react-pdf-highlighter.

Grabdone avatar Jul 27 '22 11:07 Grabdone