forked from vanielf/pdf-lib
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathtest19.ts
More file actions
28 lines (23 loc) · 809 Bytes
/
test19.ts
File metadata and controls
28 lines (23 loc) · 809 Bytes
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
import { Assets } from '../index.ts';
import { PDFDocument, StandardFonts } from '../../../dist/pdf-lib.esm.js';
export default async (assets: Assets) => {
const pdfDoc = await PDFDocument.load(assets.pdfs.simple);
const snapshot = pdfDoc.takeSnapshot();
const page = pdfDoc.getPage(0);
snapshot.markRefForSave(page.ref);
const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman);
const fontSize = 30;
const { height } = page.getSize();
page.drawText('Incremental saving is also awesome!', {
x: 50,
y: height - 8 * fontSize,
size: fontSize,
font: timesRomanFont,
});
const pdfIncrementalBytes = await pdfDoc.saveIncremental(snapshot);
const pdfBytes = new Uint8Array([
...assets.pdfs.simple,
...pdfIncrementalBytes,
]);
return pdfBytes;
};