-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf.ts
29 lines (28 loc) · 854 Bytes
/
pdf.ts
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
29
import pdf from "html-pdf";
export async function generatePdf(
html: string,
outFile: string,
options: pdf.CreateOptions = {}
) {
return new Promise<pdf.FileInfo>((resolve, reject) =>
pdf
.create(html, {
// TODO: figure out something better here
// This looks ok, but is a weird non-standard PDF size
// Can't figure out how to configure DPI, which seems to default 72 (but might be device dependent)
// https://github.com/ariya/phantomjs/issues/12685
//
// PhantomJS also has some other weird issues, like font family and weight don't seem to be respected.
width: "1000px",
height: "1300px",
...options,
})
.toFile(outFile, (err, res) => {
if (!err) {
resolve(res);
} else {
reject(err);
}
})
);
}