Detector plugin for file-type that identifies PDF (Portable Document Format) files and selected PDF-based subtypes.
This plugin goes beyond simple magic-number detection and can inspect the internal PDF structure to distinguish between generic PDF files and specific producer formats such as Adobe Illustrator (.ai).
This detector is designed for well-formed PDF files and established PDF-based subtypes. Support for corrupted or non-conforming PDFs is intentionally limited and only considered when a deviation is both common and widely accepted.
npm install @file-type/pdfThe following example shows how to add the PDF detector to file-type:
import { FileTypeParser } from 'file-type';
import { detectPdf } from '@file-type/pdf';
const parser = new FileTypeParser({
customDetectors: [detectPdf],
});
const fileType = await parser.fromFile('example.pdf');
console.log(fileType);.ai/application/illustrator: Adobe Illustrator.pdf/application/pdf: Generic Portable Document Format files
This project is licensed under the MIT License. Feel free to use, modify, and distribute it as needed.