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
        """

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