Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spaceCount calculation #5

Merged
merged 1 commit into from
Aug 16, 2022
Merged

fix spaceCount calculation #5

merged 1 commit into from
Aug 16, 2022

Conversation

Remi-p
Copy link

@Remi-p Remi-p commented Aug 15, 2022

Hi! Thank you for this repository (:.

It seems we encountered a bug with my colleagues (cc: @luiscardosooliveira).

The error was:

    RangeError: Invalid array length
      at parsePageItems (node_modules/pdf-text-reader/dist/index.js:93:25)
      at parsePage (node_modules/pdf-text-reader/dist/index.js:31:12)
      at async readPdfText (node_modules/pdf-text-reader/dist/index.js:17:20)

After investigating a little, it seems like lastItem.height can be equal to 0.

This leads to spaceCount being equal to Infinity (from line: )

const spaceCountB = Math.ceil(xDiff / lastItem.height);

As we're doing an Array(spaceCount) afterwards, it makes the library throw an error.

line += Array(spaceCount).fill('').join(' ');


Adding a condition on lastItem.height !== 0 corrects the behavior.


npm run test was launched and didn't return any errors. Please feel free to tell us if it's OK for you!

lastItem.height can be equals to 0.

This leads to spaceCount being infinite (from line:
`const spaceCountB = Math.ceil(xDiff / lastItem.height)`)

As we're doing an `Array(spaceCount)` afterwards, it makes the library throw
an error.

Adding a condition on lastItem.height !== 0 corrects the behavior.

cc: @luiscardosooliveira
@electrovir electrovir added the bug Something isn't working label Aug 16, 2022
@electrovir
Copy link
Owner

Nice work! Thank you!

@electrovir electrovir merged commit 1439c4e into electrovir:master Aug 16, 2022
@electrovir
Copy link
Owner

This has been included in version 3.0.2: https://www.npmjs.com/package/pdf-text-reader/v/3.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants