-
Notifications
You must be signed in to change notification settings - Fork 23
/
test.js
37 lines (36 loc) · 1.16 KB
/
test.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
1,async function(){
const { PDFName, PDFString, PDFDocument, StandardFonts, rgb } = require('pdf-lib')
const pdfDoc = await PDFDocument.create()
const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman)
const page = pdfDoc.addPage()
const { width, height } = page.getSize()
const fontSize = 30
page.drawText('Test pdf!! ABCDEFG', {
x:50,
y: height -4 * fontSize,
size: fontSize,
font: timesRomanFont,
color: rgb(0, 0.53, 0.71)
})
const linkAnnotation = pdfDoc.context.obj({
Type: 'Annot',
Subtype: 'Link',
Rect: [50, height - 95, 320, height - 130],
Border: [0, 0, 2],
C: [0, 0, 1],
A: {
Type: 'Action',
S: 'URI',
URI: PDFString.of(`injection)`),
}
})
const linkAnnotationRef = pdfDoc.context.register(linkAnnotation)
page.node.set(PDFName.of('Annots'), pdfDoc.context.obj([linkAnnotationRef]))
const pdfBytes = await pdfDoc.save()
const fs = require('fs')
fs.writeFile("output.pdf", new Buffer(pdfBytes), function(err){
if(err) {
console.log(err);
}
});
}();