PDF-utils with custom font causes undefined Name error
-
Hello folks,
I have JSReport running on a docker container and using a template on the pug engine with the chrome-pdf recipe. I've been trying to figure out a way that I can sign the pdf with a certificate but when I configure it via pdf-utils (or pdf-sign), I get an error with the message "A Name cannot be undefined".
Error: Error while executing pdf-utils operations. A Name cannot be undefined
at module.exports (/app/node_modules/jsreport-core/lib/util/createError.js:11:13)
at Reporter.createError (/app/node_modules/jsreport-core/lib/reporter.js:332:12)
at AsyncFunction.<anonymous> (/app/node_modules/jsreport-pdf-utils/lib/main.js:382:22)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
caused by: Error: A Name cannot be undefined
at new PDFName (/app/node_modules/jsreport-pdfjs/lib/object/name.js:14:13)
at Function.parse (/app/node_modules/jsreport-pdfjs/lib/object/name.js:109:12)
at Object.exports.parse (/app/node_modules/jsreport-pdfjs/lib/object/value.js:20:30)
at Function.parse (/app/node_modules/jsreport-pdfjs/lib/object/dictionary.js:80:30)
at Object.exports.parse (/app/node_modules/jsreport-pdfjs/lib/object/value.js:20:30)
at Function.parseInner (/app/node_modules/jsreport-pdfjs/lib/object/object.js:85:28)
at Function.parse (/app/node_modules/jsreport-pdfjs/lib/object/object.js:73:27)
at parseObject (/app/node_modules/jsreport-pdfjs/lib/object/reference.js:128:22)
at PDFReference.get [as object] (/app/node_modules/jsreport-pdfjs/lib/object/reference.js:15:17)
at Function.addObjectsRecursive (/app/node_modules/jsreport-pdfjs/lib/parser/parser.js:61:35)It seems like this could be caused by a custom google font I'm using called Inconsolata.
CSS here: https://www.cssfontstack.com/Inconsolata
If I change it to Arial or Helvetica then the pdf successfully generates but this particular custom font is needed. I have tried to find workarounds for this issue but so far have been unsuccessful so any help would be greatly appreciated. Thanks!
-
Hi,
would you be able to create a minimal playground demo replicating the error so we can take a look?
Thank you
https://playground.jsreport.net/Jan
-
Hi Jan,
My apologies for taking so long, thank you for responding so soon. Here is playground demo that reproduces the error: https://playground.jsreport.net/w/ajphillips/PMW_yuFU
Hope that helps. Thanks!
-
I don't know why, but chrome on Linux creates pdf with an invalid font name.
This is diff for pdf output when running chrome windows vs linuxIt should work to install font explicitly to the docker image without using web font. On Alpine it could be something like this:
FROM jsreport/jsreport:2.11.0 USER root RUN apk add ttf-inconsolata@edge
-
I was able to make pdf utils working also with the empty name. You can just install patch like this and use your original HTML.
RUN npm i jsreport/jsreport-pdf-utils#ec8023ec4c96b99efb2f41ebd0ca60f38f74c408
-
Excellent, the pdf-utils extension is working now with the patch. Thank you!