(bytes: Uint8Array)
| 191 | * @returns The version string (e.g., "1.4") or null if not found |
| 192 | */ |
| 193 | export function getPdfVersion(bytes: Uint8Array) { |
| 194 | if (!isPdfHeader(bytes)) { |
| 195 | return null; |
| 196 | } |
| 197 | |
| 198 | // Find the newline after the header |
| 199 | let end = 5; |
| 200 | |
| 201 | while (end < bytes.length && end < 20) { |
| 202 | const b = bytes[end]; |
| 203 | if (b === 0x0a || b === 0x0d) { |
| 204 | break; |
| 205 | } |
| 206 | end++; |
| 207 | } |
| 208 | |
| 209 | // Extract version (e.g., "1.4" from "%PDF-1.4") |
| 210 | const header = String.fromCharCode(...bytes.slice(0, end)); |
| 211 | |
| 212 | const match = header.match(/%PDF-(\d+\.\d+)/); |
| 213 | |
| 214 | return match?.[1] ?? null; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Save test output to the test-output directory for manual inspection. |
no test coverage detected