Setting custom DPI values using Aspose.Slides

Dear Team,
I tried to convert image(tiff/ jpeg/ png) to PDF by setting custom dpi resolution value as 300dpi. The image had been converted into pdf but the conversion failed to set dpi resolution value as 300 dpi.
kindly provide a workaround solution.

Attached input file:
DPI Issue.zip (1.4 MB)
Code used:

Image image = (Image)Image.load(dataDir);
PdfOptions pdfOptions = new PdfOptions();
ResolutionSetting rs=new ResolutionSetting();
rs.setHorizontalResolution(300);
rs.setVerticalResolution(300);
pdfOptions.setResolutionSettings(rs);
dataDir = fileNameWithOutExt+".pdf";
image.save(dataDir,pdfOptions);

1 Like

@resh05,

I have observed your comments. Can you please visit this thread link. This will help you out in this issue. Please share feedback with us if there is still an issue.

Hi @Adnan.Ahmad
I tried the above thread(DPI Issue - #2 by Adnan.Ahmad) you posted but was unable to get the expected output.
Above thread only gives the changes in image width,height and dpi value is automatically applied but i need to set different dpi value for different images

@resh05,

I like to inform that i have worked with your issue in detail. Can you please share more sample files along with generated result for testing purpose. Also please explain your issue in more details.

@resh05,

Please visit this thread link. I have shared sample code that will help you to achieve your requirements.

Dear @Adnan.Ahmad
Thanks for the code,it works fineā€¦
My question is could we increase or decrease the dpi value for an image? If yes, then could you please provide me a workaround solution.
Attached sample:
12.jpg (17.7 KB)
Thanks

@resh05,

I like to inform that we can change dpi value for PDF but for JPG image we have to investigate this on our end. A ticket with ID IMAGINGJAVA-1405 has been created in our issue tracking system. We will share good news with you soon.

Dear @Adnan.Ahmad
Thank you :blush:

@resh05,

You are very welcome.

1 Like

@resh05,

Can you please check following code and share feedback with us if this solution satisfy you.

RasterImage image = (RasterImage)Image.load(ā€œ12.jpgā€);
try
{
Assert.assertEquals(image.getHorizontalResolution(), 96.0, 0.001, ā€œHorizontal resolution must be equals 96 dpiā€);
Assert.assertEquals(image.getVerticalResolution(), 96.0, 0.001,ā€œVertical resolution must be equals 96 dpiā€);
image.setHorizontalResolution(300);
image.setVerticalResolution(300);
image.save(ā€œoutput.jpgā€);
}
finally
{
image.close();
}

image = (RasterImage)Image.load(ā€œoutput.jpgā€);
try
{
Assert.assertEquals(image.getHorizontalResolution(), 300.0, 0.001, ā€œHorizontal resolution must be equals 300 dpiā€);
Assert.assertEquals(image.getVerticalResolution(), 300.0, 0.001, ā€œVertical resolution must be equals 300 dpiā€);
}
finally
{
image.close();
}

Hi @Adnan.Ahmad
The code works fine.
Thank Youā€¦

@resh05,

You are very welcome.