From 5cdd8a0a865f5f97457e5f33cecc517963f15422 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Thu, 10 Nov 2022 00:00:32 +0100 Subject: [PATCH] Replace customTextRenderer in test suite and documentation Related to #1151 --- README.md | 2 +- test/Test.jsx | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 209c8a5cf..3dcd1d55b 100644 --- a/README.md +++ b/README.md @@ -405,7 +405,7 @@ Displays a page. Should be placed inside ``. Alternatively, it can h | canvasBackground | Canvas background color. Any valid `canvas.fillStyle` can be used. If you set `renderMode` to `"svg"` this prop will be ignored. | n/a | `"transparent"` | | canvasRef | A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to `` rendered by `` component. If you set `renderMode` to `"svg"` this prop will be ignored. | n/a |
  • Function:
    `(ref) => { this.myPage = ref; }`
  • Ref created using `React.createRef`:
    `this.ref = React.createRef();`

    `inputRef={this.ref}`
  • Ref created using `React.useRef`:
    `const ref = React.useRef();`

    `inputRef={ref}`
| | className | Class name(s) that will be added to rendered element along with the default `react-pdf__Page`. | n/a |
  • String:
    `"custom-class-name-1 custom-class-name-2"`
  • Array of strings:
    `["custom-class-name-1", "custom-class-name-2"]`
| -| customTextRenderer | Function that customizes how a text layer is rendered. | n/a | `` ({ str, itemIndex }) => { return `${str}` } `` | +| customTextRenderer | Function that customizes how a text layer is rendered. | n/a | `` ({ str, itemIndex }) => str && str.replace(/ipsum/g, `ipsum`) `` | | error | What the component should display in case of an error. | `"Failed to load the page."` |
  • String:
    `"An error occurred!"`
  • React element:
    `
    An error occurred!
    `
  • Function:
    `this.renderError`
| | height | Page height. If neither `height` nor `width` are defined, page will be rendered at the size defined in PDF. If you define `width` and `height` at the same time, `height` will be ignored. If you define `height` and `scale` at the same time, the height will be multiplied by a given factor. | Page's default height | `300` | | imageResourcesPath | The path used to prefix the src attributes of annotation SVGs. | n/a (pdf.js will fallback to an empty string) | `"/public/images/"` | diff --git a/test/Test.jsx b/test/Test.jsx index 5c8c563b8..f2f938af1 100644 --- a/test/Test.jsx +++ b/test/Test.jsx @@ -183,17 +183,7 @@ export default function Test() { renderTextLayer, scale: pageScale, width: pageWidth, - customTextRenderer: (textItem) => - textItem.str - .split('ipsum') - .reduce( - (strArray, currentValue, currentIndex) => - currentIndex === 0 - ? [...strArray, currentValue] - : [...strArray, 'ipsum', currentValue], - [], - ) - .join(''), + customTextRenderer: ({ str }) => str && str.replace(/ipsum/g, `ipsum`), }; }