Permalink
Browse files

Added templating feature

  • Loading branch information...
alFReD-NSH committed Dec 24, 2011
1 parent fb7d8ce commit d30168c83b91d169a75f2d1e32406a608e144672
Showing with 18 additions and 3 deletions.
  1. +16 −1 lib/document.coffee
  2. +2 −2 lib/page.coffee
View
@@ -43,6 +43,8 @@ class PDFDocument
@info[key] = val for key, val of @options.info
delete @options.info
+ @temp = @ref()
+
# Add the first page
@addPage()
@@ -77,7 +79,11 @@ class PDFDocument
@store.ref(data)
addContent: (str) ->
- @page.content.add str
+ if @haveTemp is true
+ @temp.add str
+ else
+ @page.content.add str
+
return this # make chaining possible
write: (filename, callback) ->
@@ -149,5 +155,14 @@ class PDFDocument
toString: ->
"[object PDFDocument]"
+
+ haveTemp: false
+
+ startTemp: ->
+ @haveTemp = true
+
+ endTemp: ->
+ @temp.finalize @compress
+ @haveTemp = false
module.exports = PDFDocument
View
@@ -25,14 +25,14 @@ class PDFPage
@height = dimensions[if @layout is 'portrait' then 1 else 0]
# A reference to the content of this page
- @content = @document.ref()
+ @content = @document.ref()
# The page dictionary
@dictionary = @document.ref
Type: 'Page'
Parent: @document.store.pages
MediaBox: [0, 0, @width, @height]
- Contents: @content
+ Contents: [@content, @document.temp]
# The resource dictionary
@dictionary.data['Resources'] = @document.ref

0 comments on commit d30168c

Please sign in to comment.