pdfjs
pdfjs copied to clipboard
Error when using Header/footer
I've been getting the error "TypeError: obj.toReference is not a function at Document._startPage (/home/user/niceserver/node_modules/pdfjs/lib/document.js:320:53)" whenever I try to use header or footer on a project, even the examples projects are giving the same error.
Thanks for the report! Would you mind providing a minimal example?
Here is a minimal example that is working fine for me:
const doc = new pdf.Document()
doc.pipe(fs.createWriteStream('test.pdf'))
doc.header().text("Header")
doc.footer().text("Footer")
doc.text("Works")
await doc.end()
Well, I tried to create a new project, with just fs and pdfjs, and it worked. Is there any known conflict with other modules that I might be using?
I am not aware of any module that leads to conflicts - sorry. If you are able to trim your issue down to a small example, I'd be happy to have a look
For me, the problem was custom prototype functions of Array: https://stackoverflow.com/a/32773408/13123354
My functions had been declared like:
Array.prototype.clone = function(...) ...
And now:
Object.defineProperty(Array.prototype, 'clone', {
enumerable: false,
value: function(...) ...
})