mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	feat(cli): add paper format option for PDF generation (#35589)
This commit is contained in:
		
							parent
							
								
									b32a9a05e2
								
							
						
					
					
						commit
						32d0cefc49
					
				@ -265,6 +265,7 @@ Examples:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
commandWithOpenOptions('pdf <url> <filename>', 'save page as pdf',
 | 
					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-selector <selector>', 'wait for given selector before saving as pdf'],
 | 
				
			||||||
      ['--wait-for-timeout <timeout>', 'wait for given timeout in milliseconds before saving as pdf'],
 | 
					      ['--wait-for-timeout <timeout>', 'wait for given timeout in milliseconds before saving as pdf'],
 | 
				
			||||||
    ]).action(function(url, filename, options) {
 | 
					    ]).action(function(url, filename, options) {
 | 
				
			||||||
@ -366,6 +367,7 @@ type CaptureOptions = {
 | 
				
			|||||||
  waitForSelector?: string;
 | 
					  waitForSelector?: string;
 | 
				
			||||||
  waitForTimeout?: string;
 | 
					  waitForTimeout?: string;
 | 
				
			||||||
  fullPage: boolean;
 | 
					  fullPage: boolean;
 | 
				
			||||||
 | 
					  paperFormat?: string;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function launchContext(options: Options, extraOptions: LaunchOptions): Promise<{ browser: Browser, browserName: string, launchOptions: LaunchOptions, contextOptions: BrowserContextOptions, context: BrowserContext }> {
 | 
					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);
 | 
					  const page = await openPage(context, url);
 | 
				
			||||||
  await waitForPage(page, captureOptions);
 | 
					  await waitForPage(page, captureOptions);
 | 
				
			||||||
  console.log('Saving as pdf into ' + path);
 | 
					  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.
 | 
					  // launchContext takes care of closing the browser.
 | 
				
			||||||
  await page.close();
 | 
					  await page.close();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user