Skip to main content
Glama

get_pdf_info

Extract basic PDF metadata including page count from local files or URLs, with automatic caching for online documents.

Instructions

Get basic information about a PDF file including page count.

Supports both local file paths and URLs. For URLs, the PDF will be downloaded
to a temporary directory and cached for future use.

Args:
    pdf_file_path: Path to the PDF file or URL to PDF
    
Returns:
    Basic information about the PDF file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_file_pathYes

Implementation Reference

  • The `get_pdf_info` tool handler, which retrieves basic metadata and page count from a PDF file.
    @mcp.tool()
    async def get_pdf_info(pdf_file_path: str) -> str:
        """Get basic information about a PDF file including page count.
        
        Supports both local file paths and URLs. For URLs, the PDF will be downloaded
        to a temporary directory and cached for future use.
    
        Args:
            pdf_file_path: Path to the PDF file or URL to PDF
            
        Returns:
            Basic information about the PDF file
        """
        try:
            # Resolve path (download if URL, validate if local path)
            actual_path = resolve_path(pdf_file_path)
            
            # Validate local path if not URL
            if not is_url(pdf_file_path):
                is_valid, error_msg = validate_path(pdf_file_path)
                if not is_valid:
                    return error_msg
        
        except Exception as e:
            return f"Error resolving path: {str(e)}"
        
        try:
            with open(actual_path, 'rb') as file:
                pdf_reader = PyPDF2.PdfReader(file)
                
                # Get all needed information within the with block
                total_pages = len(pdf_reader.pages)
                info = pdf_reader.metadata
                
                result = "PDF file information:\n"
                result += f"Total pages: {total_pages}\n"
                
                if info:
                    result += f"Title: {info.get('/Title', 'Unknown')}\n"
                    result += f"Author: {info.get('/Author', 'Unknown')}\n"
                    result += f"Creator: {info.get('/Creator', 'Unknown')}\n"
                    result += f"Creation date: {info.get('/CreationDate', 'Unknown')}\n"
                
                return result
            
        except FileNotFoundError:
            return f"Error: File not found '{actual_path}'"
        except Exception as e:
            return f"Error getting PDF information: {str(e)}"

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/lockon-n/pdf-tools-mcp'

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