blob: 4787f56576f4bfe514df5b9c7a9edbc5c40c3ef2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
"use server";
import { Invoice } from "@/models/invoice";
import PDFDocument from "pdfkit";
import blobStream from "blob-stream";
export async function generateInvoice(invoice: Invoice): Promise<Blob> {
const doc = new PDFDocument();
const stream = doc.pipe(blobStream());
doc.text("Invoice from " + invoice.from);
doc.end();
return new Promise((resolve, reject) => {
stream.on("finish", () => {
const blob = stream.toBlob();
resolve(blob);
});
stream.on("error", reject);
});
}
|