Browse Source
need to clean things up, add async support, test images etc. I believe some guys forked node-canvas to add some kind of image caching for when an image appears several times within a PDF document, though that may be out of scopev1.x
7 changed files with 154 additions and 21 deletions
@ -0,0 +1,39 @@ |
|||
|
|||
var Canvas = require('../') |
|||
, canvas = new Canvas(500, 500, 'pdf') |
|||
, ctx = canvas.getContext('2d') |
|||
, fs = require('fs'); |
|||
|
|||
var x, y; |
|||
|
|||
function reset() { |
|||
x = 50; |
|||
y = 80; |
|||
} |
|||
|
|||
function h1(str) { |
|||
ctx.font = '22px Helvetica'; |
|||
ctx.fillText(str, x, y); |
|||
} |
|||
|
|||
function p(str) { |
|||
ctx.font = '10px Arial'; |
|||
ctx.fillText(str, x, y += 20); |
|||
} |
|||
|
|||
reset(); |
|||
h1('PDF demo'); |
|||
p('Multi-page PDF demonstration'); |
|||
ctx.nextPage(); |
|||
|
|||
reset(); |
|||
h1('Page #2'); |
|||
p('This is the second page'); |
|||
ctx.nextPage(); |
|||
|
|||
reset(); |
|||
h1('Page #3'); |
|||
p('This is the third page'); |
|||
|
|||
fs.writeFile('out.pdf', canvas.toBuffer()); |
|||
console.log('created out.pdf'); |
@ -0,0 +1,22 @@ |
|||
|
|||
var Canvas = require('../') |
|||
, canvas = new Canvas(500, 500, 'pdf') |
|||
, ctx = canvas.getContext('2d') |
|||
, fs = require('fs'); |
|||
|
|||
var y = 80 |
|||
, x = 50; |
|||
|
|||
ctx.font = '22px Helvetica'; |
|||
ctx.fillText('node-canvas pdf', x, y); |
|||
|
|||
ctx.font = '10px Arial'; |
|||
ctx.fillText('Just a quick example of PDFs with node-canvas', x, y += 20); |
|||
|
|||
ctx.globalAlpha = .5; |
|||
ctx.fillRect(x, y += 20, 10, 10); |
|||
ctx.fillRect(x += 20, y, 10, 10); |
|||
ctx.fillRect(x += 20, y, 10, 10); |
|||
|
|||
fs.writeFile('out.pdf', canvas.toBuffer()); |
|||
console.log('created out.pdf'); |
Loading…
Reference in new issue