isPDF static method

Future<bool> isPDF(
  1. MergeInput input
)

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 {
  late FileMagicNumberType fileType;
  switch (input.type) {
    case MergeInputType.path:
      final bytes = await FileMagicNumber.getBytesFromPathOrBlob(input.path!);
      fileType = FileMagicNumber.detectFileTypeFromBytes(bytes);
      break;
    case MergeInputType.bytes:
      fileType = FileMagicNumber.detectFileTypeFromBytes(input.bytes!);
      break;
  }
  return fileType == FileMagicNumberType.pdf;
}