Skip to main content
Glama

fill_pdf_form

Fill PDF form fields by providing field name-value pairs. Accepts base64-encoded PDF, optionally flattens fields to make them non-editable. Returns filled PDF as base64.

Instructions

Fill form fields in a PDF.

Args: pdf_base64: Base64-encoded PDF file with form fields. fields: Field name-value pairs to fill. flatten: Whether to flatten the form (make fields non-editable).

Returns: Base64-encoded filled PDF.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_base64Yes
fieldsYes
flattenNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'fill_pdf_form'. Accepts pdf_base64 (str), fields (dict[str,str]), and flatten (bool). Decodes the PDF, calls dg.fill_form(), and returns a base64-encoded filled PDF.
    @mcp.tool()
    def fill_pdf_form(
        pdf_base64: str,
        fields: dict[str, str],
        flatten: bool = False,
    ) -> str:
        """Fill form fields in a PDF.
    
        Args:
            pdf_base64: Base64-encoded PDF file with form fields.
            fields: Field name-value pairs to fill.
            flatten: Whether to flatten the form (make fields non-editable).
    
        Returns:
            Base64-encoded filled PDF.
        """
        dg = _get_client()
        result = dg.fill_form(base64.b64decode(pdf_base64), fields, flatten)
        return base64.b64encode(result).decode()
  • The tool is registered as an MCP tool via the @mcp.tool() decorator on the fill_pdf_form function.
    @mcp.tool()
  • Low-level fill method on PdfFormsClient that sends a POST request to /api/pdf-forms/fill. It builds a PdfFormFillRequest and returns the filled PDF bytes.
    def fill(
        self,
        pdf: FileInput,
        fields: dict[str, str],
        *,
        flatten: bool = False,
        password: str | None = None,
    ) -> bytes:
        """Fill form fields in a PDF.
    
        Args:
            pdf: PDF file with form fields.
            fields: Field values to fill (name → value).
            flatten: Make fields non-editable after filling.
            password: Optional password for the output PDF.
    
        Returns:
            Filled PDF bytes.
        """
        request = PdfFormFillRequest(
            pdf_base64=to_base64(pdf),
            fields=fields,
            flatten=flatten,
            password=password,
        )
        return self._transport.request_bytes(
            "POST", "/api/pdf-forms/fill", json=to_dict(request)
        )
  • DocGen client's fill_form method that delegates to PdfFormsClient.fill(). This is the intermediate call made by the MCP handler.
    def fill_form(
        self,
        pdf: FileInput,
        fields: dict[str, str],
        **kwargs: Any,
    ) -> bytes:
        """Fill PDF form fields.
    
        Args:
            pdf: PDF with form fields.
            fields: Field values (name → value).
            **kwargs: Additional options (flatten, password).
    
        Returns:
            Filled PDF bytes.
        """
        return self._pdf_forms.fill(pdf, fields, **kwargs)
  • PdfFormFillRequest dataclass - the request schema used to fill PDF form fields. Contains pdf_base64, fields dict, flatten flag, and optional password.
    @dataclass
    class PdfFormFillRequest:
        """Request to fill PDF form fields.
    
        Args:
            pdf_base64: Base64-encoded PDF with form fields.
            fields: Field values to fill (name → value).
            flatten: Whether to flatten the form after filling (makes fields non-editable).
            password: Optional password for the filled PDF.
        """
    
        pdf_base64: str
        fields: dict[str, str] = field(default_factory=dict)
        flatten: bool = False
        password: str | None = None
Behavior3/5

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

Given no annotations, the description must disclose behavior. It mentions the flatten option and that it returns a base64-encoded PDF, but lacks details on error handling, missing fields, or potential side effects. It does not contradict anything, as no annotations exist.

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 concise (5 lines) and well-structured with Args and Returns. Every sentence adds value without redundancy, making it easy to parse quickly.

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

Completeness3/5

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

While the description covers basic usage and return value, it misses edge cases like what happens if fields are empty or if the PDF lacks form fields. Given the tool's simplicity and the presence of an output schema, it is adequate but not exhaustive.

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

Parameters4/5

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

Schema description coverage is 0%, so the description compensates by explaining each parameter (e.g., 'pdf_base64: Base64-encoded PDF with form fields'). This adds meaning beyond the schema's titles, though more detail (e.g., accepted formats for fields) would improve it.

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

Purpose5/5

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

The description clearly states 'Fill form fields in a PDF,' specifying a precise verb and resource. This distinguishes it from sibling tools like merge_pdfs or generate_pdf_from_html, which serve different purposes.

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

Usage Guidelines3/5

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

The description explains the tool's function and parameters but does not explicitly state when to use it versus alternatives like inspect_pdf_form (to check fields) or generate_pdf_from_html (to create new forms). No when-not or comparative guidance is provided.

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

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/dokmatiq/docgen-sdks'

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