agentcooper / react-pdf-highlighter

Set of React components for PDF annotation
https://agentcooper.github.io/react-pdf-highlighter
MIT License
973 stars 386 forks source link

Word are merging without space. #34

Open SelvaSurukam opened 5 years ago

SelvaSurukam commented 5 years ago

Hi @agentcooper.

If you see the sample deployed in https://agentcooper.github.io/react-pdf-highlighter/.

You have some predefined highlighted text. In that, one line highlighted as Impressive and highlighted text on right side panel is millions of lines of code atFacebookevery day

But actual content on pdf looks with space like millions of lines of code at Facebook every day.

So the problem is there should be space between at Facebook every day

So please help me in solving this.

agentcooper commented 5 years ago

This is a known limitation. Because PDF.js uses absolute positioning, the chunks of text are sometimes merged. What can be done: the code which gets the text from the range can be improved to take the rectangle positions into the account https://github.com/agentcooper/react-pdf-highlighter/blob/master/src/components/PdfHighlighter.js#L485.

SelvaSurukam commented 5 years ago

Hi thanks for quick reply.

When I tried to open PDF and copy text with Google Chrome Default PDf viewer, I am not getting this issue.

As you said earlier the problem in PDF.js, do you have some work around code samples to solve this or do you aware of how Google Chrome able to solve this.

agentcooper commented 5 years ago

Chrome's built-in viewer is not PDF.JS, they use a custom PDF renderer: https://opensource.google.com/projects/pdfium.

SelvaSurukam commented 5 years ago

Hi once again thanks for quick reply.

Do you have any sample to fix this issue? Because you aware of this and you might have tried some approach to solve this.

If you have anything please share it, I can continue from there, because I have to fix this issue on priority now.

agentcooper commented 5 years ago

I don't have anything working, sorry. As I said earlier, I would start with exploring the distance between the rectangles.

SelvaSurukam commented 5 years ago

Thanks, will implement and get back to you.

shalinivasudev commented 4 years ago

Did this problem get solved @SelvaSurukam ?

Naerriel commented 1 month ago

As a workaround, I get the values from window.getSelection()?.toString()