feat(cli): add paper format option for PDF generation (#35589)

This commit is contained in:
Marcin Szafranek 2025-04-14 21:26:33 +02:00 committed by GitHub
parent b32a9a05e2
commit 32d0cefc49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -265,6 +265,7 @@ Examples:
commandWithOpenOptions('pdf <url> <filename>', 'save page as pdf',
[
['--paper-format <format>', 'paper format: Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6'],
['--wait-for-selector <selector>', 'wait for given selector before saving as pdf'],
['--wait-for-timeout <timeout>', 'wait for given timeout in milliseconds before saving as pdf'],
]).action(function(url, filename, options) {
@ -366,6 +367,7 @@ type CaptureOptions = {
waitForSelector?: string;
waitForTimeout?: string;
fullPage: boolean;
paperFormat?: string;
};
async function launchContext(options: Options, extraOptions: LaunchOptions): Promise<{ browser: Browser, browserName: string, launchOptions: LaunchOptions, contextOptions: BrowserContextOptions, context: BrowserContext }> {
@ -629,7 +631,7 @@ async function pdf(options: Options, captureOptions: CaptureOptions, url: string
const page = await openPage(context, url);
await waitForPage(page, captureOptions);
console.log('Saving as pdf into ' + path);
await page.pdf!({ path });
await page.pdf!({ path, format: captureOptions.paperFormat });
// launchContext takes care of closing the browser.
await page.close();
}