Align Text and Image vertically with iText 2

為{幸葍}努か 提交于 2021-02-08 10:22:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!