PDF with only images change dpi

We have a PDF with only images. The images are of 400 dpi. Each image is on one single page. Width: 8.25; Height: 11.7 in inches
When we use the following on the PDF document and optimize the PDF, we are the assuming the dpi of images will reduce to 300. But we dont see that happening.

var optimizeOptions = new Pdf.Optimization.OptimizationOptions();
optimizeOptions.ImageCompressionOptions.ResizeImages = true;
optimizeOptions.ImageCompressionOptions.MaxResolution = 300;
pdfDocument.OptimizeResources(optimizeOptions);

Any thoughts or ideas why it might not?
OR
what we might have to do to change/reduce the DPI of an image in a PDF document?
Thanks

@kshah05

To reduce the DPI of images in a PDF document, you can use the OptimizeResources method along with specific optimization options. However, it seems that the method you are using may not be effectively changing the DPI as expected.

Here’s a step-by-step approach to ensure that the images are resized correctly:

  1. Set Up Optimization Options: You are already using the OptimizationOptions class to set the MaxResolution. Ensure that you also set the ImageQuality if you want to reduce the quality along with the resolution.

  2. Check Image Compression Options: Make sure that the ResizeImages property is set to true, which you have done. This is necessary for the optimization process to consider resizing the images.

  3. Manual DPI Adjustment: If the optimization does not yield the desired results, you may need to manually adjust the DPI of each image in the PDF. You can achieve this by accessing the images in the document and setting their DPI directly. Here’s a code snippet that demonstrates how to do this:

    Document pdfDocument = new Document("path/to/your/document.pdf");
    XImageCollection images = pdfDocument.getPages().get_Item(1).getResources().getImages();
    
    for (int i = 1; i <= images.size(); i++) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        images.get_Item(i).save(baos, 300, 300); // Set horizontal and vertical resolutions to 300 DPI
        images.get_Item(i).replace(new ByteArrayInputStream(baos.toByteArray()));
    }
    
    pdfDocument.save("path/to/your/optimized_document.pdf");
    
  4. Re-Optimize the Document: After manually adjusting the DPI of the images, you can run the optimization process again to ensure that the document size is reduced effectively.

By following these steps, you should be able to successfully change the DPI of the images in your PDF document. If you continue to experience issues, consider checking the specific properties of the images or the PDF structure that might be preventing the changes from taking effect.

If you need further assistance, feel free to ask!

Sources:
[1]: Optimize, Compress or Reduce PDF Size in Python