]> git.kianting.info Git - clo/blob - tests/pdfManipulation.ts
fix .ttc import bug
[clo] / tests / pdfManipulation.ts
1 import * as canva from "../src/canva.js";
2 import {createWriteStream} from 'fs';
3 import PDFDocument from 'pdfkit';
4
5 let hanziFont = {
6 family : "Noto Sans CJK TC",
7 size : 12,
8 textWeight : canva.TextWeight.REGULAR,
9 textStyle : canva.TextStyle.ITALIC,
10 }
11
12 let romanFont = {
13 family : "FreeSans",
14 size : 15,
15 textWeight : canva.TextWeight.BOLD,
16 textStyle : canva.TextStyle.ITALIC,
17 }
18
19 let arabicFont = {
20 family : "noto sans arabic",
21 size : 16,
22 textWeight : canva.TextWeight.REGULAR,
23 textStyle : canva.TextStyle.NORMAL,
24 }
25
26
27
28 async function foo (){
29
30 const doc = new PDFDocument();
31
32
33 let clo = await {
34 mainText : ["123 一隻貓跑過來"],
35 mainFontStyle : hanziFont,
36 PDFCanvas : doc,
37
38 }
39 clo.PDFCanvas.pipe(createWriteStream('/tmp/output.pdf'));
40
41
42
43 await canva.putText(clo, clo.mainText[0],hanziFont, 0, 100, 200);
44 await canva.putText(clo, "ag téastáil" ,romanFont, 0, 100, 300);
45 await canva.putText(clo, "اَلْعَرَبِيَّةُ‎" ,arabicFont, 0, 100, 350);
46
47
48 doc.end();
49
50 };
51
52 foo();