I have been using the old itext jar (com.lowagie) to generate some pdfs from image files. But when I upgraded to the itextpdf jar (5.5.0) the page size ends up being set to A4 (even though I call doc.setPageSize(rectangleOfCustomSize)). When I look at the pdfs side by side the new code has the image file flowing off of the page (top and right). The old page has a size of 15.81x23.32 while the new one is 8.26x11.69.
How do I change my code to fix this issue? I need to always have custom pages sizes (never standard).
Here are some code snippets.
Document document = new Document();
...
// Set image scale
image = com.itextpdf.text.Image.getInstance(file.toString());
...
int xDPI = image.getDpiX();
int yDPI = image.getDpiY();
if (xDPI != 72 || yDPI != 72) {
image.scaleAbsolute(image.getWidth() * 72f / xDPI, image.getHeight() * 72f / yDPI);
}
...
Rectangle size = new Rectangle(image.getPlainWidth(), image.getPlainHeight());
document.setPageSize(size);
Here is a screen capture of the 2 side by side.