isPDF static method
Determines whether the given file path corresponds to a PDF file.
This method uses the file's magic number (file signature) to accurately detect if the file is a PDF, regardless of its extension. This is more reliable than checking only the file extension.
Parameters:
filePath: The absolute path to the file to check
Returns: true if the file is a valid PDF, false otherwise
(including when an error occurs during detection)
Implementation
static Future<bool> isPDF(MergeInput input) async {
switch (input.type) {
case MergeInputType.path:
return await FileMagicNumber.detectFileTypeFromPathOrBlob(
input.path!) ==
FileMagicNumberType.pdf;
case MergeInputType.bytes:
return FileMagicNumber.detectFileTypeFromBytes(input.bytes!) ==
FileMagicNumberType.pdf;
}
}