-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathget-header.mjs
More file actions
13 lines (12 loc) · 717 Bytes
/
get-header.mjs
File metadata and controls
13 lines (12 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
// Important: getHeader is available from the 'pdf-parse/node' submodule
import { PDFParse } from 'pdf-parse';
// HEAD request to retrieve HTTP headers and file size without downloading the full file.
// Pass `true` to check PDF magic bytes via range request
// Optionally validates PDFs by fetching the first 4 bytes (magic bytes).
// Useful for checking file existence, size, and type before full parsing.
// Node only, will not work in browser environments.
const parser = new PDFParse({ url: 'https://bitcoin.org/bitcoin.pdf' });
const result = await parser.getHeader(true);
console.log(`Overall Result: ${result.ok}`);
console.log(`File Size: ${result.fileSize}`);
console.log(`Valid PDF: ${result.validPdf}`);