-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdfctx.js
More file actions
60 lines (45 loc) · 1.39 KB
/
pdfctx.js
File metadata and controls
60 lines (45 loc) · 1.39 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function PdfCtx(width, height) {
var margin = 10;
var doc = new jsPDF({
unit: 'pt',
format: [width+2*margin, height+2*margin],
orientation: (height > width ? 'p' : 'l') });
// doc.line(20, 20, 60, 20) // horizontal line
//doc.setLineWidth(0.5)
this.doc = doc;
this.ctx = doc.context2d;
this.ctx.autoPaging = 'false';
this.ctx.lineWidth = 2.0;
this.ctx.translate(margin,margin);
this.ctx.scale(1.0,1.0);
// doc.save("test.pdf")
}
PdfCtx.prototype.myx = function(x) {
return x;
}
PdfCtx.prototype.myy = function(y) {
return y;
}
PdfCtx.prototype.save = function(filename) {
this.doc.save(filename);
}
Object.defineProperty(PdfCtx.prototype, "strokeStyle", {set: function(x) {this.ctx.strokeStyle = x;}});
Object.defineProperty(PdfCtx.prototype, "font", {set: function(x) {this.ctx.font = x;}});
Object.defineProperty(PdfCtx.prototype, "textAlign", {set: function(x) {this.ctx.textAlign = x;}});
PdfCtx.prototype.clearRect = function(x0, y0, x1, y1) {
}
PdfCtx.prototype.beginPath = function() {
this.ctx.beginPath();
}
PdfCtx.prototype.moveTo = function(x, y) {
this.ctx.moveTo(this.myx(x), this.myy(y));
}
PdfCtx.prototype.lineTo = function(x, y) {
this.ctx.lineTo(this.myx(x), this.myy(y));
}
PdfCtx.prototype.stroke = function() {
this.ctx.stroke();
}
PdfCtx.prototype.fillText = function(text, x, y) {
this.ctx.fillText(text, this.myx(x), this.myy(y));
}