Skip to main content
Glama

playwright_save_as_pdf

Convert web pages to PDF files with specified format, background settings, and margins. Save the generated PDF to a designated output path for easy access and sharing.

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

  • The SaveAsPdfTool class provides the core handler logic for saving the current Playwright page as a PDF file using page.pdf() with configurable options.
    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}`);
        });
      }
    } 
  • Tool definition including name, description, and input schema for validation.
    {
      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"],
      },
    },
  • Switch case in handleToolCall that routes the tool call to the SaveAsPdfTool instance.
    case "playwright_save_as_pdf":
      return await saveAsPdfTool.execute(args, context);
  • src/tools.ts:471-471 (registration)
    Inclusion in BROWSER_TOOLS array for conditional browser launch handling.
    "playwright_save_as_pdf",
  • Instantiation of the SaveAsPdfTool instance in initializeTools.
    if (!saveAsPdfTool) saveAsPdfTool = new SaveAsPdfTool(server);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action without behavioral details. It doesn't mention that this likely requires an active browser context, may overwrite existing files, involve file system permissions, or describe output behavior (e.g., file path return).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately understandable without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 5 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'current page' means contextually, how the PDF is generated, error conditions, or what happens after saving (e.g., confirmation). More context is needed given the complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds no additional parameter semantics beyond implying PDF generation, which is already clear from the tool name and schema. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Save') and resource ('current page as a PDF file'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'playwright_screenshot' that also capture page content, missing explicit distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'playwright_screenshot' for image capture or other PDF-related tools. The description lacks context about prerequisites (e.g., needing an active page) or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/executeautomation/mcp-playwright'

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