Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wojtekmaj/react-pdf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.1.1
Choose a base ref
...
head repository: wojtekmaj/react-pdf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.2.0
Choose a head ref
  • 9 commits
  • 15 files changed
  • 3 contributors

Commits on Nov 21, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    e1cf160 View commit details

Commits on Nov 22, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    194c0c6 View commit details
  2. Make customTextRenderer toggleable in test suite (#1152)

    Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
    paescuj and wojtekmaj authored Nov 22, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    8e6057a View commit details
  3. Bump loader-utils from 2.0.3 to 2.0.4 in /sample/create-react-app-5 (#…

    …1172)
    
    Bumps [loader-utils](https://github.com/webpack/loader-utils) from 2.0.3 to 2.0.4.
    - [Release notes](https://github.com/webpack/loader-utils/releases)
    - [Changelog](https://github.com/webpack/loader-utils/blob/v2.0.4/CHANGELOG.md)
    - [Commits](webpack/loader-utils@v2.0.3...v2.0.4)
    
    ---
    updated-dependencies:
    - dependency-name: loader-utils
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 22, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    2cdd167 View commit details
  4. Bump loader-utils from 1.4.1 to 1.4.2 in /sample/webpack4 (#1175)

    Bumps [loader-utils](https://github.com/webpack/loader-utils) from 1.4.1 to 1.4.2.
    - [Release notes](https://github.com/webpack/loader-utils/releases)
    - [Changelog](https://github.com/webpack/loader-utils/blob/v1.4.2/CHANGELOG.md)
    - [Commits](webpack/loader-utils@v1.4.1...v1.4.2)
    
    ---
    updated-dependencies:
    - dependency-name: loader-utils
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 22, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    d46734f View commit details
  5. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    20050d3 View commit details
  6. Bump loader-utils from 2.0.3 to 2.0.4 in /test (#1174)

    Bumps [loader-utils](https://github.com/webpack/loader-utils) from 2.0.3 to 2.0.4.
    - [Release notes](https://github.com/webpack/loader-utils/releases)
    - [Changelog](https://github.com/webpack/loader-utils/blob/v2.0.4/CHANGELOG.md)
    - [Commits](webpack/loader-utils@v2.0.3...v2.0.4)
    
    ---
    updated-dependencies:
    - dependency-name: loader-utils
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored and wojtekmaj committed Nov 22, 2022
    Copy the full SHA
    a1ae3a9 View commit details
  7. Copy the full SHA
    45a19b6 View commit details
  8. v6.2.0

    wojtekmaj committed Nov 22, 2022
    Copy the full SHA
    08e7c44 View commit details
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -406,6 +406,7 @@ Displays a page. Should be placed inside `<Document />`. Alternatively, it can h
| canvasRef | A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to `<canvas>` rendered by `<PageCanvas>` component. If you set `renderMode` to `"svg"` this prop will be ignored. | n/a | <ul><li>Function:<br />`(ref) => { this.myPage = ref; }`</li><li>Ref created using `React.createRef`:<br />`this.ref = React.createRef();`<br />…<br />`inputRef={this.ref}`</li><li>Ref created using `React.useRef`:<br />`const ref = React.useRef();`<br />…<br />`inputRef={ref}`</li></ul> |
| className | Class name(s) that will be added to rendered element along with the default `react-pdf__Page`. | n/a | <ul><li>String:<br />`"custom-class-name-1 custom-class-name-2"`</li><li>Array of strings:<br />`["custom-class-name-1", "custom-class-name-2"]`</li></ul> |
| customTextRenderer | Function that customizes how a text layer is rendered. | n/a | `` ({ str, itemIndex }) => str.replace(/ipsum/g, `<mark>ipsum</mark>`) `` |
| devicePixelRatio | The ratio between physical pixels and device-independent pixels (DIPs) on the current device. | `window.devicePixelRatio` | `1` |
| error | What the component should display in case of an error. | `"Failed to load the page."` | <ul><li>String:<br />`"An error occurred!"`</li><li>React element:<br />`<div>An error occurred!</div>`</li><li>Function:<br />`this.renderError`</li></ul> |
| 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/"` |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-pdf",
"version": "6.1.1",
"version": "6.2.0",
"description": "Display PDFs in your React app as easily as if they were images.",
"main": "dist/cjs/entry.js",
"module": "dist/esm/entry.js",
6 changes: 3 additions & 3 deletions sample/create-react-app-5/yarn.lock
Original file line number Diff line number Diff line change
@@ -7873,13 +7873,13 @@ __metadata:
linkType: hard

"loader-utils@npm:^2.0.0":
version: 2.0.3
resolution: "loader-utils@npm:2.0.3"
version: 2.0.4
resolution: "loader-utils@npm:2.0.4"
dependencies:
big.js: ^5.2.2
emojis-list: ^3.0.0
json5: ^2.1.2
checksum: d055c61ce5927b64cb4af40218606603a7d3a39adb7b6eec116bb31d19203875950e478152dea056de404eced8e87e9bfd336ec636591ded040ea451f63c7d88
checksum: a5281f5fff1eaa310ad5e1164095689443630f3411e927f95031ab4fb83b4a98f388185bb1fe949e8ab8d4247004336a625e9255c22122b815bb9a4c5d8fc3b7
languageName: node
linkType: hard

12 changes: 6 additions & 6 deletions sample/webpack4/yarn.lock
Original file line number Diff line number Diff line change
@@ -5273,24 +5273,24 @@ __metadata:
linkType: hard

"loader-utils@npm:^1.2.3":
version: 1.4.1
resolution: "loader-utils@npm:1.4.1"
version: 1.4.2
resolution: "loader-utils@npm:1.4.2"
dependencies:
big.js: ^5.2.2
emojis-list: ^3.0.0
json5: ^1.0.1
checksum: ea0b648cba0194e04a90aab6270619f0e35be009e33a443d9e642e93056cd49e6ca4c9678bd1c777a2392551bc5f4d0f24a87f5040608da1274aa84c6eebb502
checksum: eb6fb622efc0ffd1abdf68a2022f9eac62bef8ec599cf8adb75e94d1d338381780be6278534170e99edc03380a6d29bc7eb1563c89ce17c5fed3a0b17f1ad804
languageName: node
linkType: hard

"loader-utils@npm:^2.0.0":
version: 2.0.3
resolution: "loader-utils@npm:2.0.3"
version: 2.0.4
resolution: "loader-utils@npm:2.0.4"
dependencies:
big.js: ^5.2.2
emojis-list: ^3.0.0
json5: ^2.1.2
checksum: d055c61ce5927b64cb4af40218606603a7d3a39adb7b6eec116bb31d19203875950e478152dea056de404eced8e87e9bfd336ec636591ded040ea451f63c7d88
checksum: a5281f5fff1eaa310ad5e1164095689443630f3411e927f95031ab4fb83b4a98f388185bb1fe949e8ab8d4247004336a625e9255c22122b815bb9a4c5d8fc3b7
languageName: node
linkType: hard

2 changes: 1 addition & 1 deletion sample/webpack5/package.json
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
"less-loader": "^11.0.0",
"style-loader": "^3.0.0",
"webpack": "^5.20.0",
"webpack-cli": "^4.7.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.0.0"
},
"resolutions": {
99 changes: 49 additions & 50 deletions sample/webpack5/yarn.lock
Original file line number Diff line number Diff line change
@@ -1805,36 +1805,36 @@ __metadata:
languageName: node
linkType: hard

"@webpack-cli/configtest@npm:^1.2.0":
version: 1.2.0
resolution: "@webpack-cli/configtest@npm:1.2.0"
"@webpack-cli/configtest@npm:^2.0.0":
version: 2.0.0
resolution: "@webpack-cli/configtest@npm:2.0.0"
peerDependencies:
webpack: 4.x.x || 5.x.x
webpack-cli: 4.x.x
checksum: a2726cd9ec601d2b57e5fc15e0ebf5200a8892065e735911269ac2038e62be4bfc176ea1f88c2c46ff09b4d05d4c10ae045e87b3679372483d47da625a327e28
webpack: 5.x.x
webpack-cli: 5.x.x
checksum: 7d1977c833c4dcd7cc30a6873bf5f79564a194e4799bcdaf8158081595409adf64e3179beada4f7b6522086c8e18ee802f7b505692d6359aab6503e8caa82de8
languageName: node
linkType: hard

"@webpack-cli/info@npm:^1.5.0":
version: 1.5.0
resolution: "@webpack-cli/info@npm:1.5.0"
dependencies:
envinfo: ^7.7.3
"@webpack-cli/info@npm:^2.0.0":
version: 2.0.0
resolution: "@webpack-cli/info@npm:2.0.0"
peerDependencies:
webpack-cli: 4.x.x
checksum: 7f56fe037cd7d1fd5c7428588519fbf04a0cad33925ee4202ffbafd00f8ec1f2f67d991245e687d50e0f3e23f7b7814273d56cb9f7da4b05eed47c8d815c6296
webpack: 5.x.x
webpack-cli: 5.x.x
checksum: d354d50dbef180066279b548e91b84372a99e1026fa1c228dcb4a6923a6aefc76e8a9c4e328e048732dc086c60fab967ff323690f170cc6a3c1a83c06bbf043e
languageName: node
linkType: hard

"@webpack-cli/serve@npm:^1.7.0":
version: 1.7.0
resolution: "@webpack-cli/serve@npm:1.7.0"
"@webpack-cli/serve@npm:^2.0.0":
version: 2.0.0
resolution: "@webpack-cli/serve@npm:2.0.0"
peerDependencies:
webpack-cli: 4.x.x
webpack: 5.x.x
webpack-cli: 5.x.x
peerDependenciesMeta:
webpack-dev-server:
optional: true
checksum: d475e8effa23eb7ff9a48b14d4de425989fd82f906ce71c210921cc3852327c22873be00c35e181a25a6bd03d424ae2b83e7f3b3f410ac7ee31b128ab4ac7713
checksum: d5cd72589d3563e21dedbd9e05102ef87f7e325a1de15fb7db0906132440556920719ce012e0f052efd1bc4c1fbaf3fb123552c5f3476339657ebf29c5c81732
languageName: node
linkType: hard

@@ -2383,20 +2383,20 @@ __metadata:
languageName: node
linkType: hard

"commander@npm:^7.0.0":
version: 7.2.0
resolution: "commander@npm:7.2.0"
checksum: 53501cbeee61d5157546c0bef0fedb6cdfc763a882136284bed9a07225f09a14b82d2a84e7637edfd1a679fb35ed9502fd58ef1d091e6287f60d790147f68ddc
languageName: node
linkType: hard

"commander@npm:^8.3.0":
version: 8.3.0
resolution: "commander@npm:8.3.0"
checksum: 0f82321821fc27b83bd409510bb9deeebcfa799ff0bf5d102128b500b7af22872c0c92cb6a0ebc5a4cf19c6b550fba9cedfa7329d18c6442a625f851377bacf0
languageName: node
linkType: hard

"commander@npm:^9.4.1":
version: 9.4.1
resolution: "commander@npm:9.4.1"
checksum: bfb18e325a5bdf772763c2213d5c7d9e77144d944124e988bcd8e5e65fb6d45d5d4e86b09155d0f2556c9a59c31e428720e57968bcd050b2306e910a0bf3cf13
languageName: node
linkType: hard

"commondir@npm:^1.0.1":
version: 1.0.1
resolution: "commondir@npm:1.0.1"
@@ -3606,10 +3606,10 @@ __metadata:
languageName: node
linkType: hard

"interpret@npm:^2.2.0":
version: 2.2.0
resolution: "interpret@npm:2.2.0"
checksum: f51efef7cb8d02da16408ffa3504cd6053014c5aeb7bb8c223727e053e4235bf565e45d67028b0c8740d917c603807aa3c27d7bd2f21bf20b6417e2bb3e5fd6e
"interpret@npm:^3.1.1":
version: 3.1.1
resolution: "interpret@npm:3.1.1"
checksum: 35cebcf48c7351130437596d9ab8c8fe131ce4038da4561e6d665f25640e0034702a031cf7e3a5cea60ac7ac548bf17465e0571ede126f3d3a6933152171ac82
languageName: node
linkType: hard

@@ -4819,7 +4819,7 @@ __metadata:
react-pdf: latest
style-loader: ^3.0.0
webpack: ^5.20.0
webpack-cli: ^4.7.0
webpack-cli: ^5.0.0
webpack-dev-server: ^4.0.0
languageName: unknown
linkType: soft
@@ -4892,12 +4892,12 @@ __metadata:
languageName: node
linkType: hard

"rechoir@npm:^0.7.0":
version: 0.7.1
resolution: "rechoir@npm:0.7.1"
"rechoir@npm:^0.8.0":
version: 0.8.0
resolution: "rechoir@npm:0.8.0"
dependencies:
resolve: ^1.9.0
checksum: 2a04aab4e28c05fcd6ee6768446bc8b859d8f108e71fc7f5bcbc5ef25e53330ce2c11d10f82a24591a2df4c49c4f61feabe1fd11f844c66feedd4cd7bb61146a
resolve: ^1.20.0
checksum: ad3caed8afdefbc33fbc30e6d22b86c35b3d51c2005546f4e79bcc03c074df804b3640ad18945e6bef9ed12caedc035655ec1082f64a5e94c849ff939dc0a788
languageName: node
linkType: hard

@@ -5015,7 +5015,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@npm:^1.14.2, resolve@npm:^1.9.0":
"resolve@npm:^1.14.2, resolve@npm:^1.20.0":
version: 1.22.1
resolution: "resolve@npm:1.22.1"
dependencies:
@@ -5028,7 +5028,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@patch:resolve@^1.14.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.9.0#~builtin<compat/resolve>":
"resolve@patch:resolve@^1.14.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>":
version: 1.22.1
resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=07638b"
dependencies:
@@ -5767,36 +5767,35 @@ __metadata:
languageName: node
linkType: hard

"webpack-cli@npm:^4.7.0":
version: 4.10.0
resolution: "webpack-cli@npm:4.10.0"
"webpack-cli@npm:^5.0.0":
version: 5.0.0
resolution: "webpack-cli@npm:5.0.0"
dependencies:
"@discoveryjs/json-ext": ^0.5.0
"@webpack-cli/configtest": ^1.2.0
"@webpack-cli/info": ^1.5.0
"@webpack-cli/serve": ^1.7.0
"@webpack-cli/configtest": ^2.0.0
"@webpack-cli/info": ^2.0.0
"@webpack-cli/serve": ^2.0.0
colorette: ^2.0.14
commander: ^7.0.0
commander: ^9.4.1
cross-spawn: ^7.0.3
envinfo: ^7.7.3
fastest-levenshtein: ^1.0.12
import-local: ^3.0.2
interpret: ^2.2.0
rechoir: ^0.7.0
interpret: ^3.1.1
rechoir: ^0.8.0
webpack-merge: ^5.7.3
peerDependencies:
webpack: 4.x.x || 5.x.x
webpack: 5.x.x
peerDependenciesMeta:
"@webpack-cli/generators":
optional: true
"@webpack-cli/migrate":
optional: true
webpack-bundle-analyzer:
optional: true
webpack-dev-server:
optional: true
bin:
webpack-cli: bin/cli.js
checksum: 2ff5355ac348e6b40f2630a203b981728834dca96d6d621be96249764b2d0fc01dd54edfcc37f02214d02935de2cf0eefd6ce689d970d154ef493f01ba922390
checksum: 514874b6625d5a0077d9f52fe67dd0528115823d15612dbdc99fece271d26825fbedd3e7b209ed7726edc8528c0e7f787acbba57929ac4cb6d0618ec1c834933
languageName: node
linkType: hard

3 changes: 3 additions & 0 deletions src/Page.jsx
Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@ export class PageInternal extends PureComponent {
const {
canvasBackground,
customTextRenderer,
devicePixelRatio,
onGetAnnotationsError,
onGetAnnotationsSuccess,
onGetTextError,
@@ -96,6 +97,7 @@ export class PageInternal extends PureComponent {
return {
canvasBackground,
customTextRenderer,
devicePixelRatio,
onGetAnnotationsError,
onGetAnnotationsSuccess,
onGetTextError,
@@ -378,6 +380,7 @@ PageInternal.propTypes = {
children: PropTypes.node,
className: isClassName,
customTextRenderer: PropTypes.func,
devicePixelRatio: PropTypes.number,
error: isFunctionOrNode,
height: PropTypes.number,
imageResourcesPath: PropTypes.string,
22 changes: 16 additions & 6 deletions src/Page/PageCanvas.jsx
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import * as pdfjs from 'pdfjs-dist/build/pdf';

import PageContext from '../PageContext';

import { getPixelRatio, isCancelException, makePageCallback } from '../shared/utils';
import { getDevicePixelRatio, isCancelException, makePageCallback } from '../shared/utils';

import { isPage, isRef, isRotate } from '../shared/propTypes';

@@ -20,8 +20,12 @@ export class PageCanvasInternal extends PureComponent {
}

componentDidUpdate(prevProps) {
const { canvasBackground, page, renderForms } = this.props;
if (canvasBackground !== prevProps.canvasBackground || renderForms !== prevProps.renderForms) {
const { canvasBackground, devicePixelRatio, page, renderForms } = this.props;
if (
canvasBackground !== prevProps.canvasBackground ||
devicePixelRatio !== prevProps.devicePixelRatio ||
renderForms !== prevProps.renderForms
) {
// Ensures the canvas will be re-rendered from scratch. Otherwise all form data will stay.
page.cleanup();
this.drawPageOnCanvas();
@@ -76,12 +80,17 @@ export class PageCanvasInternal extends PureComponent {
if (onRenderError) onRenderError(error);
};

get devicePixelRatio() {
const { devicePixelRatio } = this.props;

return devicePixelRatio || getDevicePixelRatio();
}

get renderViewport() {
const { devicePixelRatio } = this;
const { page, rotate, scale } = this.props;

const pixelRatio = getPixelRatio();

return page.getViewport({ scale: scale * pixelRatio, rotation: rotate });
return page.getViewport({ scale: scale * devicePixelRatio, rotation: rotate });
}

get viewport() {
@@ -146,6 +155,7 @@ export class PageCanvasInternal extends PureComponent {
PageCanvasInternal.propTypes = {
canvasBackground: PropTypes.string,
canvasRef: isRef,
devicePixelRatio: PropTypes.number,
onRenderError: PropTypes.func,
onRenderSuccess: PropTypes.func,
page: isPage.isRequired,
8 changes: 4 additions & 4 deletions src/Page/TextLayer.jsx
Original file line number Diff line number Diff line change
@@ -169,17 +169,17 @@ export class TextLayerInternal extends PureComponent {
this.endElement.current = end;

if (customTextRenderer) {
let itemIndex = 0;
textContent.items.forEach((item) => {
const child = this.layerElement.current.children[itemIndex];
let index = 0;
textContent.items.forEach((item, itemIndex) => {
const child = this.layerElement.current.children[index];

const content = customTextRenderer({
itemIndex,
...item,
});

child.innerHTML = content;
itemIndex += item.str && item.hasEOL ? 2 : 1;
index += item.str && item.hasEOL ? 2 : 1;
});
}

2 changes: 1 addition & 1 deletion src/shared/utils.js
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ export function dataURItoByteString(dataURI) {
return unescape(dataString);
}

export function getPixelRatio() {
export function getDevicePixelRatio() {
return (isBrowser && window.devicePixelRatio) || 1;
}

Loading