Add URL→PDF endpoint, usage tracking middleware, free tier limits

This commit is contained in:
DocFast Bot 2026-02-14 13:02:40 +00:00
parent 8e03b8ab3c
commit 6896b72e0c
5 changed files with 158 additions and 4 deletions

View file

@ -52,3 +52,40 @@ export async function renderPdf(
await page.close();
}
}
export async function renderUrlPdf(
url: string,
options: {
format?: string;
landscape?: boolean;
margin?: { top?: string; right?: string; bottom?: string; left?: string };
printBackground?: boolean;
waitUntil?: string;
} = {}
): Promise<Buffer> {
if (!browser) throw new Error("Browser not initialized");
const page: Page = await browser.newPage();
try {
await page.goto(url, {
waitUntil: (options.waitUntil as any) || "networkidle0",
timeout: 30_000,
});
const pdf = await page.pdf({
format: (options.format as any) || "A4",
landscape: options.landscape || false,
printBackground: options.printBackground !== false,
margin: options.margin || {
top: "20mm",
right: "15mm",
bottom: "20mm",
left: "15mm",
},
});
return Buffer.from(pdf);
} finally {
await page.close();
}
}