From fbcb53855e76a33f2a475e9d2f41f1182ccd2e84 Mon Sep 17 00:00:00 2001 From: Mathieu Triay Date: Tue, 7 Apr 2015 10:52:58 +0100 Subject: [PATCH] Emit an event when a page is added Use the document as the EventEmitter Update docs --- docs/getting_started.coffee.md | 5 +++++ lib/document.coffee | 2 ++ 2 files changed, 7 insertions(+) diff --git a/docs/getting_started.coffee.md b/docs/getting_started.coffee.md index bf277d4..f67ee0f 100644 --- a/docs/getting_started.coffee.md +++ b/docs/getting_started.coffee.md @@ -85,6 +85,11 @@ quite simple! doc.addPage() +To add some content every time a page is created, either by calling `addPage()` or automatically, you can use the `pageAdded` event. + + doc.on 'pageAdded', -> + doc.text "Page Title" + You can also set some options for the page, such as it's size and orientation. The `layout` property can be either `portrait` (the default) or `landscape`. diff --git a/lib/document.coffee b/lib/document.coffee index b9dff02..7cb67de 100644 --- a/lib/document.coffee +++ b/lib/document.coffee @@ -99,6 +99,8 @@ class PDFDocument extends stream.Readable # the top left rather than the bottom left @_ctm = [1, 0, 0, 1, 0, 0] @transform 1, 0, 0, -1, 0, @page.height + + @emit('pageAdded') return this