[MKT-652]:feat/FileCompressor tool quality improve #1679
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Description
The file compressor had an issue with PDF compression where PDFs were only being compressed by 5% using basic pdf-lib optimization
After an investigation I found that we could improve easily the compressor by adding:
-Real Compression Logic: The compressPDF function only used useObjectStreams and addDefaultPage flags, which barely reduced file size
-A real Implementation: There was no dedicated PDF compression module, just a basic wrapper around pdf-lib's save function
Proposed Improve
Implementation
Created a dedicated PDF compression module with multiple strategies:
1. Content Detection
- hasSelectableText(): Uses PDF.js to detect if PDF contains selectable text
- analyzePDFContent(): Analyzes PDF to determine optimal compression strategy
2. Compression Methods
1. Basic Optimization (for text-based PDFs):
- Removes metadata (title, author, subject, keywords, producer, creator)
- Enables object streams compression
- Preserves all text, links, and document structure
- Results in 5-15% compression while maintaining full functionality
2. Ultra Quality Rendering (for scanned PDFs):
- Renders each page to canvas at high resolution
- Supports PNG (lossless) or JPEG (high quality) output
- Implements 2x super-sampling for better anti-aliasing
- Uses high-quality image smoothing during rendering
- Results in 60-70% compression with good visual quality
3. Updated the main service to use the new module: