/
annotations.spec.js
109 lines (102 loc) · 2.72 KB
/
annotations.spec.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* global describe, it, jsPDF, comparePdf */
/**
* Standard spec tests
*
* These tests return the datauristring so that reference files can be generated.
* We compare the exact output.
*/
describe("Module: Annotations", () => {
beforeAll(loadGlobals);
it("should draw a closed annotation", () => {
const doc = jsPDF({ floatPrecision: 2 });
doc.createAnnotation({
type: "text",
title: "note",
bounds: {
x: 10,
y: 10,
w: 200,
h: 80
},
contents: "This is text annotation (closed by default)",
open: false
});
comparePdf(doc.output(), "closed.pdf", "annotations");
});
it("should draw an open annotation", () => {
const doc = jsPDF({ floatPrecision: 2 });
doc.createAnnotation({
type: "text",
title: "note",
bounds: {
x: 10,
y: 10,
w: 200,
h: 80
},
contents: "This is text annotation (open by default)",
open: true
});
comparePdf(doc.output(), "open.pdf", "annotations");
});
it("should draw a free text annotation", () => {
const doc = jsPDF({ floatPrecision: 2 });
doc.createAnnotation({
type: "freetext",
bounds: {
x: 0,
y: 10,
w: 200,
h: 20
},
contents: "This is a freetext annotation",
color: "#ff0000"
});
comparePdf(doc.output(), "freetext.pdf", "annotations");
});
it("should draw a link on the text with link after add page", () => {
const doc = new jsPDF({
unit: "px",
format: [200, 300],
floatPrecision: 2
});
doc.textWithLink("Click me!", 10, 10, {
url: "https://parall.ax/"
});
doc.addPage("a4");
doc.text("New page with difference size", 10, 10);
comparePdf(doc.output(), "insertLinkAddPage.pdf", "annotations");
});
it("should align text link based on the align option", () => {
var doc = new jsPDF({
unit: "px",
format: [200, 300],
floatPrecision: 2
});
doc.textWithLink(
"Left aligned Link",
doc.internal.pageSize.getWidth() / 2,
10,
{ align: "left", url: "https://www.google.com" }
);
doc.textWithLink(
"Center aligned Link",
doc.internal.pageSize.getWidth() / 2,
30,
{ align: "center", url: "https://www.google.com" }
);
doc.textWithLink(
"Justify aligned Link",
doc.internal.pageSize.getWidth() / 2,
50,
{ align: "justify", url: "https://www.google.com" }
);
doc.textWithLink(
"Right aligned Link",
doc.internal.pageSize.getWidth() / 2,
70,
{ align: "right", url: "https://www.google.com" }
);
comparePdf(doc.output(), "textLinkWithAlignOptions.pdf", "annotations");
});
});