pdfjs icon indicating copy to clipboard operation
pdfjs copied to clipboard

Error when using Header/footer

Open jm-beta opened this issue 4 years ago • 4 comments

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.

jm-beta avatar Mar 02 '20 17:03 jm-beta

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()

rkusa avatar Mar 03 '20 09:03 rkusa

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?

jm-beta avatar Mar 03 '20 11:03 jm-beta

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

rkusa avatar Mar 03 '20 16:03 rkusa

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(...) ...
})

lukashoror avatar Sep 21 '21 15:09 lukashoror