feat: complete OpenAPI docs with all Puppeteer PDF options
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
- Add scale, pageRanges, preferCSSPageSize, width, height to PdfOptions - Add headerTemplate, footerTemplate, displayHeaderFooter to docs - Pass all options through routes to browser service for HTML, Markdown, and URL endpoints - Export PdfRenderOptions interface for type reuse - Bump version to 0.4.5
This commit is contained in:
parent
f332d425ec
commit
1545df9a7b
5 changed files with 111 additions and 21 deletions
|
|
@ -218,17 +218,24 @@ export async function closeBrowser(): Promise<void> {
|
|||
instances.length = 0;
|
||||
}
|
||||
|
||||
export interface PdfRenderOptions {
|
||||
format?: string;
|
||||
landscape?: boolean;
|
||||
margin?: { top?: string; right?: string; bottom?: string; left?: string };
|
||||
printBackground?: boolean;
|
||||
headerTemplate?: string;
|
||||
footerTemplate?: string;
|
||||
displayHeaderFooter?: boolean;
|
||||
scale?: number;
|
||||
pageRanges?: string;
|
||||
preferCSSPageSize?: boolean;
|
||||
width?: string;
|
||||
height?: string;
|
||||
}
|
||||
|
||||
export async function renderPdf(
|
||||
html: string,
|
||||
options: {
|
||||
format?: string;
|
||||
landscape?: boolean;
|
||||
margin?: { top?: string; right?: string; bottom?: string; left?: string };
|
||||
printBackground?: boolean;
|
||||
headerTemplate?: string;
|
||||
footerTemplate?: string;
|
||||
displayHeaderFooter?: boolean;
|
||||
} = {}
|
||||
options: PdfRenderOptions = {}
|
||||
): Promise<Buffer> {
|
||||
const { page, instance } = await acquirePage();
|
||||
try {
|
||||
|
|
@ -245,6 +252,11 @@ export async function renderPdf(
|
|||
headerTemplate: options.headerTemplate,
|
||||
footerTemplate: options.footerTemplate,
|
||||
displayHeaderFooter: options.displayHeaderFooter || false,
|
||||
...(options.scale !== undefined && { scale: options.scale }),
|
||||
...(options.pageRanges && { pageRanges: options.pageRanges }),
|
||||
...(options.preferCSSPageSize !== undefined && { preferCSSPageSize: options.preferCSSPageSize }),
|
||||
...(options.width && { width: options.width }),
|
||||
...(options.height && { height: options.height }),
|
||||
});
|
||||
return Buffer.from(pdf);
|
||||
})(),
|
||||
|
|
@ -260,11 +272,7 @@ export async function renderPdf(
|
|||
|
||||
export async function renderUrlPdf(
|
||||
url: string,
|
||||
options: {
|
||||
format?: string;
|
||||
landscape?: boolean;
|
||||
margin?: { top?: string; right?: string; bottom?: string; left?: string };
|
||||
printBackground?: boolean;
|
||||
options: PdfRenderOptions & {
|
||||
waitUntil?: string;
|
||||
hostResolverRules?: string;
|
||||
} = {}
|
||||
|
|
@ -316,6 +324,14 @@ export async function renderUrlPdf(
|
|||
landscape: options.landscape || false,
|
||||
printBackground: options.printBackground !== false,
|
||||
margin: options.margin || { top: "0", right: "0", bottom: "0", left: "0" },
|
||||
...(options.headerTemplate && { headerTemplate: options.headerTemplate }),
|
||||
...(options.footerTemplate && { footerTemplate: options.footerTemplate }),
|
||||
...(options.displayHeaderFooter !== undefined && { displayHeaderFooter: options.displayHeaderFooter }),
|
||||
...(options.scale !== undefined && { scale: options.scale }),
|
||||
...(options.pageRanges && { pageRanges: options.pageRanges }),
|
||||
...(options.preferCSSPageSize !== undefined && { preferCSSPageSize: options.preferCSSPageSize }),
|
||||
...(options.width && { width: options.width }),
|
||||
...(options.height && { height: options.height }),
|
||||
});
|
||||
return Buffer.from(pdf);
|
||||
})(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue