forked from Marak/pdf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-demo.js
40 lines (30 loc) · 1.13 KB
/
node-demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var sys = require('sys');
var fs = require('fs');
var pdf = require('./lib/pdf').pdf;
/* create the PDF document */
var doc = new pdf();
doc.text(20, 20, 'hello, I am PDF.');
doc.text(20, 30, 'i was created using node.js version: ' + process.version);
doc.text(20, 40, 'i can also be created from the browser');
/* optional - set properties on the document */
doc.setProperties({
title: 'A sample document created by pdf.js',
subject: 'PDFs are kinda cool, i guess',
author: 'Marak Squires',
keywords: 'pdf.js, javascript, Marak, Marak Squires',
creator: 'pdf.js'
});
doc.addPage();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');
doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');
doc.drawLine(100, 100, 100, 120, 1.0, 'dashed');
doc.drawLine(100, 100, 120, 100, 1.2, 'dotted');
doc.drawLine(120, 120, 100, 120, 1.4, 'dashed');
doc.drawLine(120, 120, 120, 100, 1.6, 'solid');
doc.drawRect(140, 140, 10, 10, 'solid');
var fileName = "testFile"+new Date().getSeconds()+".pdf";
fs.writeFile(fileName, doc.output(), function(err, data){
sys.puts(fileName +' was created! great success!');
});