Skip to main content
Glama
pvinis
by pvinis

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"
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('Save') but lacks critical details: whether this requires specific permissions, if it overwrites existing files, what happens on failure, or typical performance characteristics. The description is too minimal for a mutation tool with no annotation coverage.

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, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized for a straightforward tool and front-loads the core purpose effectively.

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 mutation tool with no annotations and no output schema, the description is inadequate. It doesn't explain what the tool returns (e.g., success confirmation, file path), error conditions, or behavioral nuances. Given the complexity of PDF generation with multiple parameters, more context is needed for effective use.

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 the schema fully documents all 5 parameters. The description adds no parameter-specific information beyond what's in the schema, meeting the baseline score of 3 for high schema coverage without additional value.

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 explicitly differentiate from sibling tools like 'playwright_screenshot' which captures images rather than PDFs, preventing a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an active page context), compare it to 'playwright_screenshot' for different output formats, or specify scenarios where PDF generation is preferred over other capture methods.

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

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