Skip to main content
Glama

render_pdf_page

Convert a PDF page into an image for clear visualization, enabling users to view document content without form field highlighting.

Instructions

Generate an image of a PDF page without any highlighting

Args:
    pdf_path: Path to the PDF file
    page_num: Page number to render (0-indexed)
    zoom: Zoom factor for rendering (higher values for better quality)
    
Returns:
    Image of the specified page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
page_numNo
zoomNo

Implementation Reference

  • The main handler function for the 'render_pdf_page' tool, decorated with @mcp.tool() for registration. It opens the PDF using PyMuPDF (fitz), renders the specified page at given zoom, converts to PIL Image, then to PNG bytes, and returns an MCP Image object.
    @mcp.tool()
    def render_pdf_page(pdf_path: str, page_num: int = 0, zoom: float = 2.0) -> Image:
        """
        Generate an image of a PDF page without any highlighting
        
        Args:
            pdf_path: Path to the PDF file
            page_num: Page number to render (0-indexed)
            zoom: Zoom factor for rendering (higher values for better quality)
            
        Returns:
            Image of the specified page
        """
        try:
            doc = fitz.open(pdf_path)
            
            # Check if page number is valid
            if page_num < 0 or page_num >= len(doc):
                raise ValueError(f"Page number {page_num} is out of range (0-{len(doc)-1})")
                
            # Get the requested page
            page = doc[page_num]
            
            # Render the page as an image
            mat = fitz.Matrix(zoom, zoom)
            pix = page.get_pixmap(matrix=mat)
            
            # Convert to PIL Image
            img = PILImage.frombytes("RGB", [pix.width, pix.height], pix.samples)
            
            # Convert to bytes
            buffer = io.BytesIO()
            img.save(buffer, format="PNG")
            img_bytes = buffer.getvalue()
            
            doc.close()
            
            # Return MCP Image object
            return Image(data=img_bytes, format="png")
        except Exception as e:
            raise Exception(f"Error rendering PDF page: {str(e)}")
  • The @mcp.tool() decorator registers the render_pdf_page function as an MCP tool.
    @mcp.tool()
  • Type hints and docstring define the input schema (pdf_path: str, page_num: int=0, zoom: float=2.0) and output (Image).
    def render_pdf_page(pdf_path: str, page_num: int = 0, zoom: float = 2.0) -> Image:
        """
        Generate an image of a PDF page without any highlighting
        
        Args:
            pdf_path: Path to the PDF file
            page_num: Page number to render (0-indexed)
            zoom: Zoom factor for rendering (higher values for better quality)
            
        Returns:
            Image of the specified page
        """
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions that the tool generates an image without highlighting, which is useful, but it doesn't cover other important aspects such as performance characteristics (e.g., processing time, memory usage), error handling (e.g., what happens if the PDF path is invalid or page_num is out of range), or output format details (e.g., image type, size). This leaves gaps in understanding how the tool behaves beyond its basic function.

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 well-structured and concise, with a clear purpose statement followed by 'Args:' and 'Returns:' sections that efficiently list parameters and output. Every sentence earns its place by providing essential information without redundancy, making it easy to scan and understand 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?

Given the tool's moderate complexity (3 parameters, no annotations, no output schema), the description is partially complete. It covers the purpose and parameters well, but it lacks details on behavioral aspects like error handling or performance, and without an output schema, it doesn't fully explain the return value (e.g., image format or encoding). This makes it adequate but with clear gaps for effective tool invocation.

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?

The schema description coverage is 0%, so the description must compensate. It provides clear semantics for all three parameters: 'pdf_path' as the path to the PDF file, 'page_num' as the 0-indexed page number to render, and 'zoom' as a factor for rendering quality. This adds meaningful context beyond the schema's basic titles and types, effectively documenting the parameters despite the low schema coverage.

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 tool's purpose: 'Generate an image of a PDF page without any highlighting.' It specifies the verb ('generate'), resource ('image of a PDF page'), and a key constraint ('without any highlighting'), which distinguishes it from sibling tools like 'highlight_form_field'. However, it doesn't explicitly differentiate from other rendering or extraction tools beyond the highlighting aspect.

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 implies usage by specifying what the tool does (generate an image without highlighting), which suggests it should be used when a visual representation of a PDF page is needed without annotations. However, it lacks explicit guidance on when to use this tool versus alternatives like 'extract_text' for text content or 'list_pdfs' for file listings, and it doesn't mention any prerequisites 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

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/Wildebeest/mcp_pdf_forms'

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