Skip to content

Commit

Permalink
[api] added support for basic rectangles
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Oct 22, 2010
1 parent ca8d8ab commit e36a7d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
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";
var pdfAsDataURI = doc.output('datauri', {"fileName":fileName});

Expand Down Expand Up @@ -91,6 +93,8 @@
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){
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ <h3>demo -
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";
var pdfAsDataURI = doc.output('datauri', {"fileName":fileName});
Expand Down
9 changes: 9 additions & 0 deletions lib/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ var pdf = exports.pdf = function(){
var str = sprintf('BT %.2f %.2f Td (%s) Tj ET', x * k, (pageHeight - y) * k, pdfEscape(text));
out(str);
},
drawRect: function(x, y, w, h, style) {
var op = 'S';
if (style === 'F') {
op = 'f';
} else if (style === 'FD' || style === 'DF') {
op = 'B';
}
out(sprintf('%.2f %.2f %.2f %.2f re %s', x * k, (pageHeight - y) * k, w * k, -h * k, op));
},
drawLine: _drawLine,
setProperties: function(properties) {
documentProperties = properties;
Expand Down
3 changes: 3 additions & 0 deletions node-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ 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){
Expand Down

0 comments on commit e36a7d7

Please sign in to comment.