-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.coffee
49 lines (40 loc) · 1.24 KB
/
index.coffee
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
hummus = require 'hummus'
merge = require 'merge'
module.exports = (opts) ->
pdfWriter = hummus.createWriterToModify opts.in, {modifiedFilePath:opts.out}
pageModifier = new hummus.PDFPageModifier pdfWriter, opts.pageNumber
ctx = pageModifier.startContext().getContext()
cfg =
font : pdfWriter.getFontForFile "#{__dirname}/SourceSansPro-Regular.ttf"
size : 14
colorspace : 'gray'
color : 0x00
{
write: (x, y, txt) ->
ctx.writeText txt, x, y, cfg
this
end : () ->
pageModifier.endContext().writePage()
pdfWriter.end()
cfg: (cfgIn) ->
cfg = merge cfg, cfgIn
if cfg.fontPath
cfg.font = pdfWriter.getFontForFile cfg.fontPath
delete cfg.fontPath
this
image: (x, y, path, opts = {}) ->
ctx.drawImage x, y, path, opts
this
page: (nPage) ->
pageModifier.endContext().writePage()
pageModifier = new hummus.PDFPageModifier pdfWriter, nPage
ctx = pageModifier.startContext().getContext()
this
restoreCfg: () ->
cfg =
font : pdfWriter.getFontForFile "#{__dirname}/SourceSansPro-Regular.ttf"
size : 14
colorspace : 'gray'
color : 0x00
this
}