compressPdf static method

Future<CompressResult> compressPdf(
  1. String sourcePath, {
  2. CompressionLevel level = CompressionLevel.medium,
})

Compress the PDF at sourcePath with the given level.

Throws a PlatformException if compression fails.

Implementation

static Future<CompressResult> compressPdf(
  String sourcePath, {
  CompressionLevel level = CompressionLevel.medium,
}) async {
  final map = await PdfCompressorPlatform.instance.compress(
    sourcePath: sourcePath,
    level: switch (level) {
      CompressionLevel.low => 'low',
      CompressionLevel.medium => 'medium',
      CompressionLevel.high => 'high',
    },
  );

  if (map == null) {
    throw PlatformException(
      code: 'compress_failed',
      message: 'Compression returned null',
    );
  }
  return CompressResult.fromMap(map);
}