Skip to main content
PDF generation requires the pdf capability. Start the server with --caps=pdf to enable this tool.
Playwright MCP provides PDF generation capabilities, allowing you to save web pages as PDF documents. This is useful for creating reports, archiving web content, or generating printable versions of web pages.

Enabling PDF Capability

To use PDF generation tools, start the MCP server with the pdf capability:
npx @playwright/mcp-server --caps=pdf
You can combine it with other capabilities:
npx @playwright/mcp-server --caps=vision,pdf,testing

browser_pdf_save

Save the current page as a PDF document.
filename
string
File name to save the PDF to. Defaults to page-{timestamp}.pdf if not specified. Prefer relative file names to stay within the output directory.
Read-only: Yes
// Example: Save page as PDF with custom filename
{
  "tool": "browser_pdf_save",
  "arguments": {
    "filename": "report.pdf"
  }
}
// Example: Save with default filename (page-{timestamp}.pdf)
{
  "tool": "browser_pdf_save",
  "arguments": {}
}

Use Cases

Generate Reports

Create PDF reports from web dashboards or analytics pages:
// Navigate to dashboard
{ "tool": "browser_navigate", "arguments": { "url": "https://example.com/dashboard" } }

// Wait for data to load
{ "tool": "browser_wait_for", "arguments": { "time": 2 } }

// Save as PDF
{ "tool": "browser_pdf_save", "arguments": { "filename": "monthly-report.pdf" } }

Archive Web Content

Preserve web content as PDF for archival purposes:
// Navigate to article
{ "tool": "browser_navigate", "arguments": { "url": "https://blog.example.com/article" } }

// Save article as PDF
{ "tool": "browser_pdf_save", "arguments": { "filename": "article-archive.pdf" } }

Batch PDF Generation

Generate multiple PDFs from different pages:
// Page 1
{ "tool": "browser_navigate", "arguments": { "url": "https://example.com/page1" } }
{ "tool": "browser_pdf_save", "arguments": { "filename": "page1.pdf" } }

// Page 2
{ "tool": "browser_navigate", "arguments": { "url": "https://example.com/page2" } }
{ "tool": "browser_pdf_save", "arguments": { "filename": "page2.pdf" } }

// Page 3
{ "tool": "browser_navigate", "arguments": { "url": "https://example.com/page3" } }
{ "tool": "browser_pdf_save", "arguments": { "filename": "page3.pdf" } }

Create Printable Versions

Generate printer-friendly PDFs of web content:
// Navigate to content
{ "tool": "browser_navigate", "arguments": { "url": "https://docs.example.com" } }

// Click print-friendly version button if available
{ "tool": "browser_click", "arguments": { "element": "Print view button", "ref": "ref_123" } }

// Save as PDF
{ "tool": "browser_pdf_save", "arguments": { "filename": "documentation.pdf" } }

PDF Formatting Tips

Always wait for dynamic content to fully load before generating PDFs. Use browser_wait_for with appropriate time or text conditions.
The PDF will reflect the current browser viewport size. Use browser_resize to set an appropriate width for PDF generation:
{ "tool": "browser_resize", "arguments": { "width": 1200, "height": 800 } }
Many websites have special CSS for printing. The PDF will use these print stylesheets if they exist, which may differ from the on-screen view.
Some pages use lazy loading for images. Scroll through the page before generating the PDF to ensure all images are loaded:
// Scroll to bottom to trigger lazy loading
{ "tool": "browser_evaluate", "arguments": { "function": "() => window.scrollTo(0, document.body.scrollHeight)" } }
{ "tool": "browser_wait_for", "arguments": { "time": 1 } }
// Scroll back to top
{ "tool": "browser_evaluate", "arguments": { "function": "() => window.scrollTo(0, 0)" } }
// Generate PDF
{ "tool": "browser_pdf_save", "arguments": { "filename": "complete.pdf" } }

File Naming

When specifying filenames for PDFs:
  • Relative paths: Preferred. Will be saved in the output directory.
    { "filename": "report.pdf" }
    { "filename": "reports/monthly-report.pdf" }
    
  • Absolute paths: Also supported, but relative paths are recommended.
    { "filename": "/home/user/documents/report.pdf" }
    
  • Default naming: If no filename is provided, a timestamped name is used.
    // Creates: page-1709740800000.pdf
    { }
    
Use descriptive filenames that indicate the content and date, e.g., analytics-report-2024-03.pdf

Combining with Other Tools

PDF generation works well with other Playwright MCP tools:
// Complete workflow: Navigate, interact, and generate PDF

// 1. Navigate to page
{ "tool": "browser_navigate", "arguments": { "url": "https://example.com/report" } }

// 2. Set date range
{ "tool": "browser_click", "arguments": { "element": "Date picker", "ref": "ref_100" } }
{ "tool": "browser_select_option", "arguments": { "element": "Month dropdown", "ref": "ref_101", "values": ["March"] } }

// 3. Wait for report to generate
{ "tool": "browser_wait_for", "arguments": { "text": "Report complete" } }

// 4. Resize for optimal PDF layout
{ "tool": "browser_resize", "arguments": { "width": 1400, "height": 900 } }

// 5. Save as PDF
{ "tool": "browser_pdf_save", "arguments": { "filename": "march-report.pdf" } }

Common Issues

If you get an error about PDF capability not being enabled, make sure you started the server with --caps=pdf.
If content is missing from the PDF:
  • Wait longer for dynamic content to load
  • Scroll through the page to trigger lazy-loaded elements
  • Check if the page uses JavaScript to render content
If the PDF layout looks wrong:
  • Adjust the browser viewport size with browser_resize
  • Check if the site has print-specific CSS that affects layout
  • Some interactive elements may not render well in PDF
If the PDF file isn’t where you expect:
  • Use relative paths to save in the output directory
  • Check the tool response for the actual save location
  • Verify you have write permissions to the target directory

Take Screenshot

Capture page as image instead of PDF

Browser Resize

Adjust viewport size for optimal PDF layout

Wait For

Wait for content to load before generating PDF