From 8e7c1ae3f64c520002b7b988c9e87491291712d8 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Tue, 10 Apr 2012 05:54:22 -0700 Subject: [PATCH] added pdf-images.js example --- examples/pdf-images.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/pdf-images.js diff --git a/examples/pdf-images.js b/examples/pdf-images.js new file mode 100644 index 0000000..ccf5ff7 --- /dev/null +++ b/examples/pdf-images.js @@ -0,0 +1,40 @@ + +var Canvas = require('../') + , Image = Canvas.Image + , 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); +} + +function img(src) { + var img = new Image; + img.src = src; + ctx.drawImage(img, x, y += 20); + y += img.height; +} + +reset(); +h1('PDF image demo'); +p('This is an image embedded in a PDF'); +img('examples/images/squid.png'); +p('Figure 1.0 - Some squid thing'); +ctx.nextPage(); + +fs.writeFile('out.pdf', canvas.toBuffer()); +console.log('created out.pdf'); \ No newline at end of file