]> git.kianting.info Git - clo/blob - tests/pdfManipulation.ts
20231016:basic font guessing and `putText` function
[clo] / tests / pdfManipulation.ts
1 import * as canva from "../src/canva.js";
2 import { PDFDocument } from "pdf-lib";
3 var fontkit = require('@pdf-lib/fontkit');
4 import {writeFileSync} from 'fs';
5
6 let hanziFont = {
7 name : "思源黑體",
8 size : 12,
9 textWeight : canva.TextWeight.BOLD,
10 textStyle : canva.TextStyle.ITALIC,
11 }
12
13
14 async function foo (){
15
16 let c = await PDFDocument.create();
17
18 let clo = await {
19 mainText : ["123"],
20 mainFontStyle : hanziFont,
21 PDFCanvas : c,
22
23 }
24
25 clo.PDFCanvas.registerFontkit(fontkit);
26 const page = clo.PDFCanvas.addPage();
27
28 await canva.putText(clo, clo.mainText[0],hanziFont, 0, 100, 200);
29
30 const pdfBytes = await clo.PDFCanvas.save();
31
32 writeFileSync('/tmp/test.pdf', pdfBytes);
33
34 };
35
36 foo();