问题
I'm trying to print an Image and a text next to each other into a PdfPCell
. The image is bigger than the font size, so the row height is increased. iText renders the Text at the bottom of the baseline (First example).
But I want the text to be vertically aligned in the middle of the cell (Second example). What can I do to change this? I know I can change the alignment of the cell, but that doesn't change anything.
PdfPCell getImageAndText(byte[] image, String text, int originalDimension){
final Image pdfImg = Image.getInstance(image);
//Scale to 16pt.
pdfImg.scalePercent(16 * 100f / originalDimension);
Phrase image = new Phrase(new Chunk(pdfImg, 0, 0));
//Create Cell with image
final PdfPCell cell = new PdfPCell(image);
//Add text to cell
cell.addElement(new Phrase(text, getFont()));
return cell;
}
I am using iText 2.1.7
来源:https://stackoverflow.com/questions/50167410/align-text-and-image-vertically-with-itext-2