I use the library "com.itextpdf: itextg" to create PDF files. My requirement is to add images to a PDF file in A4 format, one image per page.
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image image = Image.getInstance(stream.toByteArray());
image.scaleToFit(PageSize.A4);
document.add(image);
By default, images are added as aligned to the top, and some space remains free at the bottom of the PDF document page.
I want to center the image so that equal space remains on all sides and the image is centered.
I know that we have a setAbsolutePosition method, but this requires absoluteX and absoluteY. I need something like CENTER_HORIZONTAL and CENTER_VERTICAL. Can someone help in creating a PDF with the image centered (vertically and horizontally)?
source
share