-
Notifications
You must be signed in to change notification settings - Fork 169
/
FormXObjectTest.js
56 lines (47 loc) · 1.19 KB
/
FormXObjectTest.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
var hummus = require('../hummus');
describe('FormXObjectTest', function() {
it('should complete without error', function() {
var pdfWriter = hummus.createWriter(__dirname + '/output/XObjectContent.pdf');
var page = pdfWriter.createPage(0,0,595,842);
var pageContent = pdfWriter.startPageContentContext(page);
pageContent.q()
.k(100,0,0,0)
.re(100,500,100,100)
.f()
.Q();
pdfWriter.pausePageContentContext(pageContent);
// define a form
var xobjectForm = pdfWriter.createFormXObject(0,0,200,100);
xobjectForm.getContentContext().q()
.k(0,100,100,0)
.re(0,0,200,100)
.f()
.Q();
pdfWriter.endFormXObject(xobjectForm);
// continue page content, and use form
pageContent.q()
.cm(1,0,0,1,200,600)
.doXObject(xobjectForm)
.Q()
.q()
.G(0.5)
.w(3)
.m(200,600)
.l(400,400)
.S()
.Q()
.q()
.cm(1,0,0,1,200,200)
.doXObject(xobjectForm)
.Q();
pdfWriter.writePage(page);
// 2nd page only uses the form
var secondPage = pdfWriter.createPage(0,0,595,842);
pdfWriter.startPageContentContext(secondPage).q()
.cm(1,0,0,1,300,500)
.doXObject(xobjectForm)
.Q();
pdfWriter.writePage(secondPage);
pdfWriter.end();
});
});