Working example of JSReport using pdf-utils to render a header and footer in NodeJS
-
Posted about this here too: https://github.com/jsreport/jsreport-pdf-utils/issues/36
I'm trying to generate a PDF using jsreport with the
pdf-utils
extension in a Node.js environment.What I need:
- An example of how to generate a PDF using
pdf-utils
from Node.js. - Ideally, with custom logic like:
- A different header on the first page.
- No header or footer on the last page.
🔍 What I’ve Tried
I found some examples in the jsreport playground, which are useful but UI-focused. Unfortunately, they don't show how to translate the logic into Node.js code.
The official docs (pdf-utils docs) are a bit hard to follow, especially when it comes to:
- Where to place the JS properties like
pdfUtils.operations
when calling jsreport programmatically. - How to link header/footer templates via code instead of using the UI.
Here’s an example screenshot of what I see in the playground, but I can’t map it back to code:
🛠️ Problem: Extension Compatibility Error
Even installing the
jsreport-pdf-utils
package leads to this error:
Extension “pdf-utils” is not compatible with “core” extension. Missing “.requires” information in “pdf-utils” definition
There’s zero documentation or references online regarding this
"requires"
field and what needs to be set up to resolve this issue.
🙏 Request
Could you please provide:
- A working Node.js example using
pdf-utils
. - Clarification on how to:
- add headers and footer. Bonus if the example adds a different header for the first page and no header and footer on the last page
- Attach template headers and footers programmatically. Bonus if the header and footer can be in the same html as the main content
- Any tips on fixing the
"requires"
compatibility error when installingjsreport-pdf-utils
.
- An example of how to generate a PDF using