( filePath: string, )
| 117 | * Returns `null` if pdfinfo is not available or if the page count cannot be determined. |
| 118 | */ |
| 119 | export async function getPDFPageCount( |
| 120 | filePath: string, |
| 121 | ): Promise<number | null> { |
| 122 | const { code, stdout } = await execFileNoThrow('pdfinfo', [filePath], { |
| 123 | timeout: 10_000, |
| 124 | useCwd: false, |
| 125 | }) |
| 126 | if (code !== 0) { |
| 127 | return null |
| 128 | } |
| 129 | const match = /^Pages:\s+(\d+)/m.exec(stdout) |
| 130 | if (!match) { |
| 131 | return null |
| 132 | } |
| 133 | const count = parseInt(match[1]!, 10) |
| 134 | return isNaN(count) ? null : count |
| 135 | } |
| 136 | |
| 137 | export type PDFExtractPagesResult = { |
| 138 | type: 'parts' |
no test coverage detected