clo/tests/pdfManipulation.ts

52 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

import * as canva from "../src/canva.js";
2023-10-24 00:41:15 +08:00
import {createWriteStream} from 'fs';
import PDFDocument from 'pdfkit';
let hanziFont = {
2023-10-24 00:41:15 +08:00
family : "Noto Sans CJK TC",
size : 12,
2023-10-24 00:41:15 +08:00
textWeight : canva.TextWeight.REGULAR,
fontStyle : canva.FontStyle.ITALIC,
2023-10-24 00:41:15 +08:00
}
let romanFont = {
family : "FreeSans",
size : 15,
textWeight : canva.TextWeight.BOLD,
fontStyle : canva.FontStyle.ITALIC,
}
2023-10-24 00:41:15 +08:00
let arabicFont = {
family : "noto sans arabic",
size : 16,
textWeight : canva.TextWeight.REGULAR,
fontStyle : canva.FontStyle.NORMAL,
2023-10-24 00:41:15 +08:00
}
async function foo (){
2023-10-24 00:41:15 +08:00
const doc = new PDFDocument();
2023-10-24 00:41:15 +08:00
let clo = await {
mainText : ["123 一隻貓跑過來"],
mainTextStyle : hanziFont,
2023-10-24 00:41:15 +08:00
PDFCanvas : doc,
}
clo.PDFCanvas.pipe(createWriteStream('/tmp/output.pdf'));
2023-10-24 00:41:15 +08:00
await canva.putText(clo, clo.mainText[0],hanziFont, 0, 100, 200);
await canva.putText(clo, "ag téastáil" ,romanFont, 0, 100, 300);
await canva.putText(clo, "اَلْعَرَبِيَّةُ‎" ,arabicFont, 0, 100, 350);
2023-10-24 00:41:15 +08:00
doc.end();
};
foo();