First it is: If the png saved as "C:/DATASTORE/slide-"+(i+1)+".png" is incorrect, the slide in the PDF will also not be right.
And this:. Your piece of code does not show us how you create the Document object. The default page size is A4 in portrait orientation. It goes without saying that images larger than 595 x 842 do not fit this page.
Now the answer: There are two ways to solve this problem.
Or you will resize the image ( not with setWidthPercentage() if you have not calculated the actual percentage) and you will add it to the position (0, 0) so that it does not take the fields into account. For instance:
image.scaleToFit(595, 842); image.setAbsolutePosition(0, 0); doc.add(image); doc.newPage();
The best solution would be to adapt the page size to the image size.
Document doc = new Document(new Rectangle(image.getScaledWidth(), image.getScaledHeight()));
If the image size changes, you can resize the page when adding such images:
doc.setPageSize(new Rectangle(image.getScaledWidth(), image.getScaledHeight())); doc.newPage(); image.setAbsolutePosition(0, 0); doc.add(image);
It is important to understand that the new page size will only take effect after doc.newPage();
CAVEAT 1: If your PDF file contains only the last slide, you probably put all the slides on one page, and the last slide covers them all. You should call the newPage() method every time you add an image (as it was done in the code snippet in my answer).
CAVEAT 2: Your statement is incorrect. According to the API docs, there is a setPageSize(Rectangle rect) method, maybe you are using the wrong Rectangle class. If you have not followed my advice (which IMHO would not have been reasonable), you are probably looking for com.lowagie.text.Rectangle instead of java.awt.Rectangle .
CAVEAT 3: This is similar to CAVEAT 2, there really are no such methods in the java.awt.Image class, but, as described in the API docs, the com.itextpdf.text.Image class has getScaleWidth() and getScaledHeight() .