thegrizzlylabs / geniusscan-sdk-demo

Demo apps for Genius Scan SDK
30 stars 39 forks source link

Pdf File Size #67

Closed komritza closed 1 year ago

komritza commented 1 year ago

Hi guys, I was wondering is there a way to reduce file size of created pdf file? We are getting mixed results where the file size are in between 200KB(cash invoice)-900KB(A4). Created pdf has only one page. Our implementation looks like this:

1) Start genius scan and store enhancedUrl in the state

      final scanConfiguration = {
        'source': 'camera',
        'multiPage': false,
      };
      final scanResult =
          await FlutterGeniusScan.scanWithConfiguration(scanConfiguration);

      if (scanResult['scans'][0]['enhancedUrl'] != null &&
          scanResult['scans'][0]['enhancedUrl'].isNotEmpty) {
        return scanResult['scans'][0]['enhancedUrl'];
      }

2) Create pdf from enhancedUrls before an upload

  final tempDir = await getTemporaryDirectory();

      final date = DateTime.now().asInvoiceDateString;

      final filePath = '${tempDir.path}/$prefixForPdfFileName-$date.pdf';

      final pages = <Map<String, String>>[];

      for (final p in imageFilePaths) {
        pages.add({'imageUrl': p});
      }

      final document = {'pages': pages};

      final documentGenerationConfiguration = {'outputFileUrl': filePath};

      await FlutterGeniusScan.generateDocument(
          document, documentGenerationConfiguration);

      return filePath;

We expected better results then by using normal camera in flutter regarding file sizes. Is there a way to compress pdf or such? Any help/hint would be highly appreciated.

guillaume-tgl commented 1 year ago

Right now, enhanced images are stored in JPEG, except when you use the Monochrome filter, in which case they are stored as optimized PNG. We plan to improve the file size of scans enhanced with the B&W filter too.

Have you tried to play with the jpegQuality parameter to see if you get smaller files?

komritza commented 1 year ago

Where do I set this parameter? Here?

var scanConfiguration = {
            'source': 'camera',
            'multiPage': true,
            'jpegQuality': 50, => Is this the right place?
            'ocrConfiguration': {
              'languages': ['eng'],
              'languagesDirectoryUrl': languageFolder.path
            }
          };

I could not find it in the docs.

guillaume-tgl commented 1 year ago

Yes. Here is the documentation: https://pub.dev/documentation/flutter_genius_scan/latest/flutter_genius_scan/FlutterGeniusScan/scanWithConfiguration.html