some special texts can't be matched when I use Page.customTextRenderer try to match and highlight that user inputed keyword
See original GitHub issueBefore you start - checklist
- I followed instructions in documentation written for my React-PDF version
- I have checked if this bug is not already reported
- I have checked if an issue is not listed in Known issues
- If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo
Description
This is displayed in Chrome
This is displayed by react-pdf
This is part of codes:
{selFile && !!selFile.isPdf && (
<Document
file={selFile.attachment_path}
options={options}
onLoadSuccess={onDocumentLoadSuccess}
onPassword={onDocumentPassword}
loading={<Spin size="large" />}
>
<div
className={cs('content', 'pdf', {
'zoom-in': canZoomByGesture && scale < maxScale,
'zoom-out': canZoomByGesture && scale >= maxScale
})}
onWheelCapture={canZoomByGesture ? onWheelCapture : undefined}
style={childStyle}
>
<div className='insideImgWr'>
<Page
pageNumber={page}
scale={scale + 0.4}
loading={<Spin size="large" />}
canvasRef={canvasRef}
customTextRenderer={customTextRenderer}
/>
<WaterMarkConsumer>
<div className='insideWatermark' />
</WaterMarkConsumer>
</div>
</div>
</Document>
)}
const customTextRenderer = useCallback((textItem) => {
if (!textItem) return null;
return highlightPattern(textItem.str, resultsList && resultsList.length ? searchString || '' : '');
}, [resultsList, searchString]);
function highlightPattern(text: string, pattern: string) {
const splitText = text.split(pattern);
console.log('xxx highlightPattern: ', text);
if (splitText.length <= 1) {
return text;
}
const matches = text.match(pattern);
return splitText.reduce(
(arr, element, index) =>
// @ts-ignore
matches[index]
? [...arr, element, <mark key={index} className='gallery-hightlight'>{matches[index]}</mark>]
: [...arr, element],
[]
);
}
Steps to reproduce
compare between Chrome PDF viewer and react-pdf of displaying a Chinese PDF. One row content has part missing disaplayed, but it is displayed correctly at Chrome PDF viewer.
Expected behavior
displayed correctly
Actual behavior
missing displayed
Additional information
No response
Environment
- Browser (if applicable):Chrome
- React-PDF version:5.6.0
- React version:17.0.2
- Webpack version (if applicable):5.65.0
Issue Analytics
- State:
- Created a year ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
React-pdf "Highlight text on the page" is not working
I am trying to implement React-pdf pdf highlighting feature: import React, { useMemo, useState } from 'react'; // import { Document, Page } ......
Read more >Create A React Search Bar That Highlights Your Results
Takes a text input; Filters the results containing said text; Highlighting that very text. I'd made something similar to this a long time ......
Read more >Highlight Searched Text With Javascript | HTML, CSS & JS
... highlight words on search using Javascript. The user enters some text in the search box and hits the search button. All the...
Read more >Viewing online file analysis results for 'tmp53_x2rlm'
String Context Stream UID
https://api.mojang.com Domain/IP reference 850444b606a5c7f3fae0c2057...
https://meteorclient.com/api/online/ping Domain/IP reference 850444b606a5c7f3fae0c2057...
os.name Domain/IP reference 850444b606a5c7f3fae0c2057...
Read more >Working with PDF in React - Medium
But any further manipulations with the PDF becomes… ... text matching each other , the mark tag returns the match that gets highlighted...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve configured cMaps and when I unset pdfjs.GlobalWorkerOptions.workerSrc, the not-displayed texts now is displayed
This issue was closed because it has been stalled for 14 days with no activity.