get_pdf_page_count
Get the total page count of a PDF file by specifying its absolute file path.
Instructions
Get the total number of pages in a PDF file
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the PDF file |
Implementation Reference
- src/index.ts:101-114 (registration)Tool registration in TOOLS array with name 'get_pdf_page_count' and input schema requiring filePath
{ name: 'get_pdf_page_count', description: 'Get the total number of pages in a PDF file', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Absolute path to the PDF file', }, }, required: ['filePath'], }, }, - src/index.ts:104-114 (schema)Input schema for get_pdf_page_count: requires filePath as a string
inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Absolute path to the PDF file', }, }, required: ['filePath'], }, }, - src/index.ts:261-273 (handler)Handler case in CallToolRequestSchema switch statement; calls getPageCount and returns 'Total pages: X'
case 'get_pdf_page_count': { const { filePath } = args as { filePath: string }; const pageCount = await getPageCount(filePath); return { content: [ { type: 'text', text: `Total pages: ${pageCount}`, }, ], }; } - src/pdf-tools.ts:68-78 (helper)Core implementation: reads PDF file, uses PDFParse to get info, returns total page count
export async function getPageCount(filePath: string): Promise<number> { try { const dataBuffer = await fs.readFile(filePath); const parser = new PDFParse({ data: dataBuffer }); const result = await parser.getInfo(); await parser.destroy(); return result.total; } catch (error) { throw new Error(`Failed to get page count: ${error instanceof Error ? error.message : String(error)}`); } } - src/index.ts:10-15 (helper)Import of getPageCount from pdf-tools.js helper module
import { extractTextFromPDF, extractMetadata, extractTextFromPages, searchInPDF, getPageCount,