]> git.kianting.info Git - uann/blob - src/pdfManipulate.ts
add matchRange
[uann] / src / pdfManipulate.ts
1 import { readFileSync, writeFileSync } from "fs";
2 import { PDFDocument } from "pdf-lib";
3 var fontkit = require('@pdf-lib/fontkit');
4
5 export async function pdfGenerate(){
6
7 const pdfDoc = await PDFDocument.create()
8 const page = pdfDoc.addPage()
9
10 pdfDoc.registerFontkit(fontkit);
11 const fontBytes = readFileSync("/usr/share/fonts/uming.ttf");
12 const font2 = await pdfDoc.embedFont(fontBytes, {subset:true})
13
14 const fontBytes2 = readFileSync("/usr/share/fonts/truetype/noto/NotoSansArabic-Light.ttf")
15
16 const font3 = await pdfDoc.embedFont(fontBytes2, {subset:true})
17
18 page.drawText("x=20, y=20", {x : 20, y : 20})
19 page.drawText("x:20, y:100 天地人", {x : 20, y : 100, font: font2})
20 page.drawText("عربي", {x : 50, y : 150, font: font3})
21
22 const pdfBytes = await pdfDoc.save();
23
24 writeFileSync('/tmp/test.pdf', pdfBytes);
25 }