Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pageAdded event not called for first page with autoFirstPage: true #1529

Open
nstdspace opened this issue Jun 23, 2024 · 1 comment
Open

Comments

@nstdspace
Copy link

Bug Report

See title.

const pdf = new PDFDocument();
pdf.on("pageAdded", () => {
    pdf.text("header");
  });

This code will not add the text "header" on the first page as expected. The first by default auto generated page does not
leed to the event "pageAdded" being invoked, thus the callback does not run.

  • pdfkit version: 0.15.0
  • Node version: v20.11.0
  • Browser version (if applicable): serverless (nuxt)
  • Operating System: Mac OS
@liborm85
Copy link
Collaborator

The problem is that the first page is added when the PDFDocument object is created (const pdf = new PDFDocument();), and this correctly triggers pageAdded event. However, the event handler is registered later (pdf.on("pageAdded", ()...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants