Skip to content

[Android] Compressed PDFs corrupted and cannot be opened after using PDFCompressor #26

@aliffaizar

Description

@aliffaizar

When compressing a PDF on Android using PDFCompressor, he output file is corrupted. Rendering the compressed file with react-native-pdf-jsi fails.
here the logs:

Android Bundled 1436ms node_modules\expo-router\entry.js (1740 modules)
[react-native-pdf-jsi] Remember to install peer dependencies:
  - react-native-blob-util
  - @react-native-async-storage/async-storage
 LOG  📤 ExportManager: Initialized (version undefined)
 LOG  📦 PDFCompressor: Checking native availability...
 LOG  📦 PDFCompressor: PDFExporter exists: true
 LOG  📦 PDFCompressor: PDFExporter.compressPDF exists: true
 LOG  📦 PDFCompressor: Native streaming compression available
 LOG  📱 PDFJSI: JSI availability on android: AVAILABLE
 LOG  🚀 PDFJSI: High-performance JSI mode enabled
 LOG  📥 [Pdf] onChange received: pageChanged full message: pageChanged|1|1
 LOG  📥 [Pdf] onChange received: loadComplete full message: loadComplete|1|191.0|270.0|/data/user/0/com.anonymous.FINAL/cache/DocumentPicker/6e88edc1-e465-4ff7-8475-3cfd2e6a08c3.pdf|[]
 LOG  📥 [Pdf] Processing loadComplete event
 LOG  📁 [Pdf] loadComplete - Path extraction: {"final": "/data/user/0/com.anonymous.FINAL/cache/DocumentPicker/6e88edc1-e465-4ff7-8475-3cfd2e6a08c3.pdf", "fromInstance": "/data/user/0/com.anonymous.FINAL/cache/DocumentPicker/6e88edc1-e465-4ff7-8475-3cfd2e6a08c3.pdf", "fromNativeMessage": "/data/user/0/com.anonymous.FINAL/cache/DocumentPicker/6e88edc1-e465-4ff7-8475-3cfd2e6a08c3.pdf", "fromState": "/data/user/0/com.anonymous.FINAL/cache/DocumentPicker/6e88edc1-e465-4ff7-8475-3cfd2e6a08c3.pdf", "hasPathInMessage": true, "originalMessageLength": 6}
 LOG  📁 [Pdf] Calling onLoadComplete callback with: {"height": 270, "pages": 1, "path": "/data/user/0/com.anonymous.FINAL/cache/DocumentPicker/6e88edc1-e465-4ff7-8475-3cfd2e6a08c3.pdf", "width": 191}
 LOG  📦 PDFCompressor: Starting compression with preset 'print'
 LOG  📦 PDFCompressor: Input file size: 0.06 MB
 LOG  📦 PDFCompressor: Using native streaming compression (level: 3)
 LOG  📦 PDFCompressor: Calling PDFExporter.compressPDF...
 LOG  📦 PDFCompressor: Native compression result: {"compressedSize": 58136, "compressionRatio": 0.9606715579350915, "durationMs": 2, "originalSize": 60516, "outputPath": "/data/user/0/com.anonymous.FINAL/cache/DocumentPicker/6e88edc1-e465-4ff7-8475-3cfd2e6a08c3_compressed_1772394256765.pdf", "spaceSavedPercent": 3.9328442064908486, "success": true}
 LOG  📦 PDFCompressor: Compression complete!
 LOG     📊 0.06 MB → 0.06 MB (3.9% saved)
 LOG     ⏱️ 12ms (4.8 MB/s)
 LOG  📱 PDFJSI: JSI availability on android: AVAILABLE
 LOG  🚀 PDFJSI: High-performance JSI mode enabled
 LOG  📥 [Pdf] onChange received: error full message: error|cannot create document: File not in PDF format or corrupted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions