We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

XImage.Save(file- format- resolution) ignores resolution

I am attempting to reduce the size of my PDF files by replacing images with “shrunken” images.

To shrink the images, I am attempting to use XImage.Save() with a resolution of 144 DPI.

The size of the image saved is not reduced in any way; and calling Resources.Images.Replace() seems to be resulting in a larger file than the original!

What can I do to make this work correctly?

The attached .zip file contains three files:
Original: (S)TEST Color 600 highest.pdf
Exported Image: (S)TEST Color 600 highest.pdf.Page 1.1.Bmp
Final: (S)TEST Color 600 highest.pdf.final.pdf

Here is the conversion function:

private static void ReduceImageSizes(string inFile, string outFile, int pixelsPerInch) {
pdf.Document pdfDocument = new pdf.Document(inFile);

foreach (pdf.Page page in pdfDocument.Pages) {
int idx = 1;
foreach (pdf.XImage image in page.Resources.Images) {
try {
System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Bmp;
string filename = IBSCompression.MakeTempFilename(inFile, "Page " + idx, fmt.ToString());
using (var imageStream = new FileStream(filename, FileMode.CreateNew)) {

image.Save(imageStream, fmt, pixelsPerInch);

// todo: resize image to (image.Width * pixelsPerInch) * (image.Height * pixelsPerInch)

imageStream.Seek(0, SeekOrigin.Begin);
page.Resources.Images.Replace(idx, imageStream);
}
} catch (Exception) {
// ignore the exception
}
idx = idx + 1;
}

}
pdfDocument.Save(outFile);
}

Hi Earl,


We are sorry for the inconvenience caused. While testing the scenario with Aspose.Pdf for NET 8.7.0, We have managed to notice the reported issue on our side and logged it in our bug tracking system as PDFNEWNET-36144 for further investigation and resolution. We will notify you as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

I just made a small modification - my original code was not including the pixelsPerInch in the call to Save().

The problem still exists, even when passing the “resolution” parameter

Hi Earl,


Thanks for sharing the information.

We will definitely consider this information during the resolution of this problem. Please note that as soon as we have made some significant progress towards the resolution of this issue, we would be more than happy to update you with the status of correction. Please be patient and spare us little time.

The issues you have found earlier (filed as PDFNEWNET-36144) have been fixed in Aspose.Pdf for .NET 8.8.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,

I’m currently using Aspose.Pdf for .Net 8.8.0 and I’m still seeing the issue with the image resolution parameter value being ignored.

I’ve tried extracting the image to various file formats each with 3 different resolution values, 50, 100 and 200 but the extracted image is always at the same resolution.

I’m using XImage.Save(stream, format, resolution)

Was this issue actually fixed?

Thanks

Tim

Hi Tim,

We are sorry for the inconvenience caused. The resolution ppi / dpi has no effect on the file size. It is only information about how large the image should be in physical dimensions, i.e. how to convert the pixel size into inches. When you resave the image using a different resolution, the file will be completely identical, except for those two values. Currently XImage API does not support parameters that reduce image size like quality, etc.
You can find more information over this link:

http://www.lanoie.net/classes/Photoshop/DigitalGraphics/lectures/lecture3.html

However to fix the size issue we have logged another feature request as PDFNEWNET-36519 for further investigation and resolution. We will keep you updated about the issue resolution progress via this forum thread.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-36519) have been fixed in Aspose.Pdf for .NET 9.7.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Tim,


As suggested above the resolution ppi / dpi has no effect on the file size. It’s only information about how large the image should be in physical dimensions, i.e. how to convert the pixel size into inches. When you resave the image using a different resolution, the file will be completely almost identical, except for those two values. The Aspose.Pdf solution sets the resolution parameter during image.Save().

However, If you wants to reduce the size of the image then you may use following following solutions.


const string myDir = @“c:”;<o:p></o:p>

Document pdfDocument = new Aspose.Pdf.Document(myDir + "(S)TEST Color 600 highest.pdf");

// optimize the file size

Document.OptimizationOptions op = new Document.OptimizationOptions();

op.ImageQuality = 10;

op.CompressImages = true;

pdfDocument.OptimizeResources(op);

pdfDocument.Save(myDir + "Images_Compressed_output_optimize_10.pdf");


Please feel free to contact us for any further assistance.


Best Regards,