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 fileInput Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pdf_file_path | Yes |
Implementation Reference
- pdf_tools_mcp/server.py:432-480 (handler)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)}"