You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
646 B

9 years ago
var fs = require('fs')
var Canvas = require('..')
9 years ago
var canvas = new Canvas(500, 500, 'pdf')
var ctx = canvas.getContext('2d')
9 years ago
var x, y
9 years ago
function reset () {
x = 50
y = 80
}
9 years ago
function h1 (str) {
ctx.font = '22px Helvetica'
ctx.fillText(str, x, y)
}
9 years ago
function p (str) {
ctx.font = '10px Arial'
ctx.fillText(str, x, (y += 20))
}
9 years ago
reset()
h1('PDF demo')
p('Multi-page PDF demonstration')
ctx.addPage()
9 years ago
reset()
h1('Page #2')
p('This is the second page')
ctx.addPage()
9 years ago
reset()
h1('Page #3')
p('This is the third page')
9 years ago
fs.writeFile('out.pdf', canvas.toBuffer(), function (err) {
if (err) throw err
console.log('created out.pdf')
})