Skip to main content
Glama

playwright_save_as_pdf

Convert the current webpage into a PDF file with customizable settings like page format, margins, and background graphics. Ideal for saving or sharing web content in a printable format.

Instructions

Save the current page as a PDF file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameNoName of the PDF file (default: page.pdf)
formatNoPage format (e.g. 'A4', 'Letter')
marginNoPage margins
outputPathYesDirectory path where PDF will be saved
printBackgroundNoWhether to print background graphics

Implementation Reference

  • SaveAsPdfTool class containing the execute handler method that performs the PDF saving using Playwright's page.pdf()
    export class SaveAsPdfTool extends BrowserToolBase { /** * Execute the save as PDF tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { const filename = args.filename || 'page.pdf'; const options = { path: path.resolve(args.outputPath || '.', filename), format: args.format || 'A4', printBackground: args.printBackground !== false, margin: args.margin || { top: '1cm', right: '1cm', bottom: '1cm', left: '1cm' } }; await page.pdf(options); return createSuccessResponse(`Saved page as PDF: ${options.path}`); }); }
  • Input schema definition for the playwright_save_as_pdf tool, specifying parameters like outputPath, filename, format, etc.
    { name: "playwright_save_as_pdf", description: "Save the current page as a PDF file", inputSchema: { type: "object", properties: { outputPath: { type: "string", description: "Directory path where PDF will be saved" }, filename: { type: "string", description: "Name of the PDF file (default: page.pdf)" }, format: { type: "string", description: "Page format (e.g. 'A4', 'Letter')" }, printBackground: { type: "boolean", description: "Whether to print background graphics" }, margin: { type: "object", description: "Page margins", properties: { top: { type: "string" }, right: { type: "string" }, bottom: { type: "string" }, left: { type: "string" } } } }, required: ["outputPath"], }, },
  • Registration and dispatch in the main tool handler switch statement, routing calls to SaveAsPdfTool.execute
    case "playwright_save_as_pdf": return await saveAsPdfTool.execute(args, context);
  • Instantiation of the SaveAsPdfTool instance in initializeTools function
    if (!saveAsPdfTool) saveAsPdfTool = new SaveAsPdfTool(server);
  • src/tools.ts:424-424 (registration)
    Inclusion in BROWSER_TOOLS array for conditional browser launch handling
    "playwright_save_as_pdf"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pvinis/mcp-playwright-stealth'

If you have feedback or need assistance with the MCP directory API, please join our Discord server