UNPKG

pdf-decomposer

Version:

📚 Extract text and images (as buffers) from PDF files using native parsing and OCR with Tesseract.

24 lines (23 loc) • 592 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isFileValid = isFileValid; /** * Check if file is valid throw error if not * @param buffer File buffer */ function isFileValid(buffer) { if (!isMimeValid(buffer)) { throw new Error('File is not a pdf'); } } /** * Check if file is a pdf * @param buffer File buffer * @returns boolean true if pdf */ function isMimeValid(buffer) { if (!buffer || buffer.length < 4) return false; // PDF: always start with "%PDF" return buffer.subarray(0, 4).toString() === '%PDF'; }