MCPcopy Create free account
hub / github.com/LibPDF-js/core / getPdfVersion

Function getPdfVersion

src/test-utils.ts:193–215  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

191 * @returns The version string (e.g., "1.4") or null if not found
192 */
193export 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.

Callers 1

index.test.tsFile · 0.90

Calls 3

isPdfHeaderFunction · 0.85
sliceMethod · 0.80
matchMethod · 0.80

Tested by

no test coverage detected