How to Fit a Presentation Slide to a Graphics Object Using Aspose.Slides for Java?

I am trying to render a slide to a graphics 2d object using the below code.

ISlide slide =  pres.getSlides().get_Item(pageNum);
slide.renderToGraphics(renderOptions, g2D);

But the rendered graphics image has the slide image to one corner. I tried options of slide.renderToGraphics(renderOptions, g2D, dimension) and slide.renderToGraphics(renderOptions, g2D, scalex, scaley) but none of them are giving the right output.
My zoom level is 2.5 as per the 72 pixel calculation. Can you please suggest how to render a slide to a graphics image fitting to its exact size given the zoom level if needed.

@mirnalini,
Thank you for posting the question.

To investigate the case and help you, we need more details. Please try to isolate the problem and share the following files and information:

  • sample presentation file
  • minimal compilable code example
  • output files
  • OS version on which the rendering was performed
  • JDK version in your app
  • Aspose.Slides version you used

Please find the attached zip file containing the java code and the output of execution and the file sample used.
aspose.zip.zip (9.8 MB)

@mirnalini,
Thank you for the details. I am working on the issue and will get back to you soon.

@mirnalini,
Thank you for your patience. Please try using the following code example.

Presentation pres = new Presentation("testrender.ppt");

for (int index = 0; index < pres.getSlides().size(); index++) {
    ISlide slide = pres.getSlides().get_Item(index);
    BufferedImage image = slide.getThumbnail(2.5f, 2.5f);
    File file = new File("image" + index + ".jpg");
    ImageIO.write(image, "png", file);
}

pres.dispose();

You can also use a third-party code to change DPI in the BufferedImage object.

@andrey.potapov Yes writing to a buffered image works with some sizing issues. But we are evaluating this for replacing an existing third party in our code. We wanted to render directly to the graphics object rather than we getting the buffered image and then writing to the graphics object because we see a margin on the right which is getting cut off .

 BufferedImage image = slide.getThumbnail(new Dimension((int)(slideSize.getWidth()*zoomLevel), (int)(slideSize.getHeight()*zoomLevel)));
 g2Dnew.drawImage(image, null, 0, 0);

@mirnalini,
Unfortunately, I don’t know what you pass to the graphics parameter of the Testsliderender.render method in the code example you provided. Could you please share a complete standalone code example that shows the problem?