-
Notifications
You must be signed in to change notification settings - Fork 142
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
TypeError: Cannot read property '12' of undefined #305
Comments
Thanks for the report. The repo is here: https://github.com/rkusa/linebreak |
After further investigation, it's failing on more than just line breaks. I commented out most of the code. Only creating the doc and adding a cell, then calling const doc = new pdf.Document({
padding: 40,
font: require('pdfjs/font/Helvetica'),
})
doc.cell(result.title) // result.title = '2001-2003 - New Hampshire-New Hampshire Troopers Association-CBA'
doc.asBuffer() Results in this error...
Hoping you'll have time to address this as our users are unable to download any of these generated PDFs and it's an important functionality of our platform. |
Does
const fs = require("fs");
const pdf = require("pdfjs");
async function main() {
try {
const doc = new pdf.Document({
padding: 40,
font: require("pdfjs/font/Helvetica"),
});
doc.pipe(fs.createWriteStream("output.pdf"));
doc.cell(
"2001-2003 - New Hampshire-New Hampshire Troopers Association-CBA"
);
await doc.end();
} catch (err) {
console.log("Caught error:");
console.error(err);
}
}
main(); Snippet above also works for the string mentioned in the initial post:
|
No it does not, and in fact, if I substitute Did some testing with lorem ipsum. See below code comments. doc.cell('Lorem i') // Doesn't work - Throws "Cannot read properties of undefined (reading '39')"
doc.cell('Lorem ') // Works
return doc.asBuffer() I'm using v2.4.7 and I'm on an M1 Mac if that makes any difference. Our api runs on arm64 architecture as well. Could that be the issue? |
Works for me too on 2.4.7 and an M1. I also run pdfjs 2.4.7 in production and have never seen this error. That is quite an odd one. Can you post the line in
|
That's correct, the // if not handled already, use the pair table
let shouldBreak = false
switch (pairTable[this.curClass][this.nextClass]) { Package is |
Doesn't look altered by any transformation. I am afraid that I am out of ideas for now. While I could adjust the const fs = require("fs");
const pdf = require("pdfjs");
async function main() {
try {
const doc = new pdf.Document({
padding: 40,
font: require("pdfjs/font/Helvetica"),
});
doc.pipe(fs.createWriteStream("output.pdf"));
doc.cell("Lorem i");
await doc.end();
} catch (err) {
console.log("Caught error:");
console.error(err);
}
}
main(); |
Yep, getting the same error running just that snippet. Referencing the line 99 in linebreak.js.
When I can find the time I'll try to put a codesandbox together to reproduce. Been busy as of late. |
Here is a Stackblitz as a starting point if that helps: https://stackblitz.com/edit/js-vvyqad?file=index.js |
Works in stackblitz: https://js-vppx4v.stackblitz.io
Could this have anything to do with it... I'm having another issue with module resolution (probably caused by webpack) causing the error
The error goes away if I change... const pdfDoc = new pdf.Document({ font: require('pdfjs/font/Helvetica') }) to... ```javascript
const pdfDoc = new pdf.Document({ font: require('pdfjs/font/Helvetica.js') }) I'm currently using Could this be causing the issue I'm unable to repro in stackblitz? |
I think the bundling/transformation is most probably the cause, as it would explain why I cannot reproduce it (and why it hasn't been reported before). |
I have a string that contains line breaks
\n
. After adding that string as text to a cell then calling asBuffer, I'm getting the following error.The
@rkusa/linebreaker
repo is no longer around (or at least the github link referenced from npm is invalid), but the original repository, foliojs/linebreak, that it was based off looks like it has recent updates that aren't reflected in your version.Here's my snippet of code that I'm trying to execute.
And, if it helps, here's the string from
keyTerm.content
that's causing issues.The text was updated successfully, but these errors were encountered: