We have constraint with PDFs shared with partners which cannot be over 200K per page, we are trying to optimize image Only Scanned PDF with Aspose.PDF with no success.
“ ScannedPDF, Sample1.pdf ”, 2 pages , 2 images , 715 136 bytes , images shown with poppler
page | num | Type | width | height | Color | comp | bpc | enc | interp | object | ID | x-ppi | y-ppi | size | ratio |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 0 | image | 2480 | 3507 | Gray | 1 | 8 | image | no | 16 | 0 | 300 | 300 | 655K | 7.7% |
2 | 1 | image | 2480 | 3507 | Gray | 1 | 8 | image | no | 18 | 0 | 300 | 300 | 35.2K | 0.4% |
ScannedPDF, Sample1, Compressed, with Apose.pdf (697.5 KB) | |||||||||||||||
ScannedPDF, Sample1, Compressed, with LovePDF.pdf (116.2 KB) | |||||||||||||||
ScannedPDF, Sample1.pdf (698.4 KB) | |||||||||||||||
ScannedPDF, Sample2, Compressed, with Apose.pdf.pdf (1.1 MB) | |||||||||||||||
ScannedPDF, Sample2.pdf (1.1 MB) |
Code used to optimize PDF.
License lic = new License();
lic.SetLicense(fileName);
using (var doc = new Document(fileName))
{
var optimizeOptions = new OptimizationOptions
{
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
RemoveUnusedStreams = true,
AllowReusePageContent = true
};
optimizeOptions.ImageCompressionOptions.CompressImages = true;
optimizeOptions.ImageCompressionOptions.ResizeImages = true;
optimizeOptions.ImageCompressionOptions.MaxResolution = 150 ;
optimizeOptions.ImageCompressionOptions.ImageQuality = 20 ;
doc.OptimizeResources(optimizeOptions);
doc.Save(compressFileName);
}
Results after compression, 714 207 bytes , less 0,13% and the images are still with 300 ppi with no compression 83% less .
page | num | type | width | height | color | comp | bpc | enc | interp | object | ID | x-ppi | y-ppi | size | ratio |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 0 | image | 2480 | 3507 | gray | 1 | 8 | image | no | 16 | 0 | 300 | 300 | 655K | 7.7% |
2 | 1 | image | 2480 | 3507 | gray | 1 | 8 | image | no | 18 | 0 | 300 | 300 | 35.2K | 0.4% |
If we use a simple tool like LovePDF , we get results 119 031 bytes, less c:
page | num | type | width | height | color | comp | bpc | enc | interp | object | ID | x-ppi | y-ppi | size | ratio |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 0 | image | 1240 | 1754 | gray | 1 | 8 | jpeg | no | 8 | 0 | 150 | 151 | 111K | 5.2% |
2 | 1 | image | 1240 | 1754 | gray | 1 | 8 | jpeg | no | 16 | 0 | 150 | 151 | 2397B | 0.1% |
Please advise how to proceed.
TIA,
Pedro