Pdfmake: linebreaker.js

Created on 21 Jan 2018  路  11Comments  路  Source: bpampuch/pdfmake

Can anyone explain this to me? Did I miss something in the download? Is there a work around?

Thanks!

reak/src/linebreaker.js:122
switch (pairTable[this.curClass][this.nextClass]) {
^

TypeError: Cannot read property 'undefined' of undefined

All 11 comments

Explain what you want to do and attach some example for reproduce of it.

I receive this anytime I run any of the examples. This one is the basics.js

var fonts = {
Roboto: {
normal: '/QOpenSys/QIBM/ProdData/OPS/Node6/fonts/Roboto/Roboto-Regular.ttf',
bold: '/QOpenSys/QIBM/ProdData/OPS/Node6/fonts/Roboto/Roboto-Medium.ttf',
italics: '/QOpenSys/QIBM/ProdData/OPS/Node6/fonts/Roboto/Roboto-Italic.ttf',
bolditalics: '/QOpenSys/QIBM/ProdData/OPS/Node6/fonts/Roboto/Roboto-MediumItalic.ttf'
}
};

var PdfPrinter = require('/QOpenSys/QIBM/ProdData/OPS/Node6/lib/node_modules/pdfmake/src/printer.js');
var printer = new PdfPrinter(fonts);
var fs = require('fs');

var docDefinition = {
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};

var pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(fs.createWriteStream('pdfs/basics.pdf'));
pdfDoc.end();

When executing the following fails:

reak/src/linebreaker.js:122
switch (pairTable[this.curClass][this.nextClass]) {
^

TypeError: Cannot read property 'undefined' of undefined
at LineBreaker.nextBreak (/QOpenSys/QIBM/ProdData/OPS/Node6/li

I don't know how to simulate it.
What version of Nodejs do you use?

6.11.5

It happens anytime I try to write text to the PDF. For example:

var fonts = {
Roboto: {
normal: 'fonts/Roboto-Regular.ttf',
bold: 'fonts/Roboto-Medium.ttf',
italics: 'fonts/Roboto-Italic.ttf',
bolditalics: 'fonts/Roboto-MediumItalic.ttf'
}
};

var PdfPrinter = require('../src/printer');
var printer = new PdfPrinter(fonts);
var fs = require('fs');

var docDefinition = {
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};

var pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(fs.createWriteStream('pdfs/basics.pdf'));
pdfDoc.end();

Variable pairTable is loaded from pairs.js file, but i don't know why is variable undefined and not loaded pairs.js file.

I was unable to reproduce the issue you were having taking the following steps:

  • In a new directory, I ran npm init then npm install roboto-fontface pdfmake --save.
  • Next I created a new file index.js (see below) and created a pdf directory.
  • Finally I ran node index.js and the pdf was generated in the directory specified.

It would seem likely that you have something specific in your env that is causing the issue and it is not the module itself. Here is that index.js file contents

var PdfPrinter = require('pdfmake/src/printer');
var fs = require('fs');

var fonts = {
  Roboto: {
    normal: 'node_modules/roboto-fontface/fonts/roboto/Roboto-Regular.ttf',
    bold: 'node_modules/roboto-fontface/fonts/roboto/Roboto-Medium.ttf',
    italics: 'node_modules/roboto-fontface/fonts/roboto/Roboto-Italic.ttf',
    bolditalics: 'node_modules/roboto-fontface/fonts/roboto/Roboto-MediumItalic.ttf'
  }
};

var printer = new PdfPrinter(fonts);

var docDefinition = {
  content: [
    'First paragraph',
    'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
  ]
};

var pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(fs.createWriteStream('pdfs/basics.pdf'));
pdfDoc.end();

@lcurcio Hi. Please try the following:

cd /QOpenSys/QIBM/ProdData/OPS/Node6/lib/node_modules/pdfmake/node_modules/linebreak/src
mv classes.trie classes.trie.old
node generate_data.js

or alternatively replace node_modules/linebreak/src/classes.trie file with one from this archive classes.trie.zip

Then retest. Let me know whether your issue is resolved this way.

@gnidorah - - - The renaming failed but installing the classes.trie from your .zip solved my problem. Thank you so much. Is the version newer or older than the default one? Is this something that might happen again if I upgrade?

Please don't forget to claim the bounty, you earned it!

@lcurcio The same as original, just re-generated on a big endian machine like "IBM I" POWER system you use. After update you may need to replace that file again. I will try fix linebreak code or at least create an issue with details so linebreak author could fix it. Will let you know.

I had exactly the same issue and the suggested solution worked, thank you. Would definitely prefer not having to manually overwrite some node_module files, though.

@KerimG

Would definitely prefer not having to manually overwrite some node_module files, though.

I've created a PR in linebreak repository for that https://github.com/devongovett/linebreak/pull/9
Also created new issue dedicated to the problem https://github.com/devongovett/linebreak/issues/8

Was this page helpful?
0 / 5 - 0 ratings