【发布时间】:2013-06-05 06:44:10
【问题描述】:
我正在使用 iText PDF 2.1.7 创建 PDF。任何人都知道iText PDF是否可以拉伸单个字符的高度(右花括号,ASCII 125)?
拉伸花括号的高度取决于前一个单元格的高度。 (请原谅我的示例图片,上大括号应该比下大括号高。
如果无法拉伸单个字符的高度,您可以建议任何其他仍使用 iText PDF 库的解决方法吗?
非常感谢。
我现在使用的是 iText 5.4.0 版。
我在缩放图像高度时遇到问题。此外,虽然我复制了单元格的位置,但图像的位置错误。大括号底部不显示。
您知道我缩放图像的方式和定位方式有什么问题吗?谢谢。
public void cellLayout(PdfPCell cell, Rectangle position,
PdfContentByte[] canvases) {
try {
BaseFont bf = BaseFont.createFont(
CreatePDFCurlyBrace.DEFAULT_ENGLISH_FONT_TTF, BaseFont.IDENTITY_H,
BaseFont.EMBEDDED);
String curlyBrace = "}";
float width = bf.getWidthPoint(curlyBrace, 12);
float height = bf.getAscentPoint(curlyBrace, 12)
- bf.getDescentPoint(curlyBrace, 12);
PdfTemplate template = this.cb.createTemplate(width, height);
template.beginText();
template.setFontAndSize(bf, 12);
template.setTextMatrix(0, bf.getDescentPoint(curlyBrace, 12));
template.showText(curlyBrace);
template.endText();
// Scale the image so that its height corresponds
// with the height of the cell
Image img = Image.getInstance(template);
img.scaleToFit(1000f, position.getHeight());
img.setAbsolutePosition(position.getRight(), position.getBottom());
cb.addImage(img);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
【问题讨论】: