This commit is contained in:
jason
2026-03-19 16:38:41 -05:00
parent 39fd876d51
commit ce2d52db53
2 changed files with 14 additions and 4 deletions

View File

@@ -1,8 +1,15 @@
import puppeteer from "puppeteer"; import puppeteer, { PaperFormat } from "puppeteer";
import { env } from "../config/env.js"; import { env } from "../config/env.js";
export async function renderPdf(html: string) { interface PdfOptions {
format?: PaperFormat;
width?: string;
height?: string;
margin?: { top?: string; right?: string; bottom?: string; left?: string };
}
export async function renderPdf(html: string, options?: PdfOptions) {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
executablePath: env.PUPPETEER_EXECUTABLE_PATH, executablePath: env.PUPPETEER_EXECUTABLE_PATH,
headless: true, headless: true,
@@ -14,7 +21,10 @@ export async function renderPdf(html: string) {
await page.setContent(html, { waitUntil: "networkidle0" }); await page.setContent(html, { waitUntil: "networkidle0" });
const pdf = await page.pdf({ const pdf = await page.pdf({
format: "A4", format: options?.width || options?.height ? undefined : (options?.format || "A4"),
width: options?.width,
height: options?.height,
margin: options?.margin,
printBackground: true, printBackground: true,
preferCSSPageSize: true, preferCSSPageSize: true,
}); });

View File

@@ -219,7 +219,7 @@ function buildShippingLabelPdf(options: {
</div> </div>
</body> </body>
</html> </html>
`); `, { width: "4in", height: "6in", margin: { top: "0", right: "0", bottom: "0", left: "0" } });
} }
function buildBillOfLadingPdf(options: { function buildBillOfLadingPdf(options: {