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:

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 {
  final FileMagicNumberType fileType;
  switch (input) {
    case PathMergeInput(:final path):
      final bytes = await FileMagicNumber.getBytesFromPathOrBlob(path);
      fileType = FileMagicNumber.detectFileTypeFromBytes(bytes);
    case BytesMergeInput(:final bytes):
      fileType = FileMagicNumber.detectFileTypeFromBytes(bytes);
    case UrlMergeInput(:final url):
      final bytes = await getUrlBytes(url);
      fileType = FileMagicNumber.detectFileTypeFromBytes(bytes);
  }
  return fileType == FileMagicNumberType.pdf;
}