小编use*_*552的帖子

使用itext中心旋转文本

我正在转换使用在线编辑器创建的文档.我需要能够使用它的中心点旋转文本,而不是(0,0).

由于Image使用中心旋转,我认为这可以工作,但事实并非如此.任何人都知道如何使用itext中的中心点旋转文本?

float fw = bf.getWidthPoint(text, textSize);
float fh = bf.getAscentPoint(text, textSize) - bf.getDescentPoint(text, textSize); 
PdfTemplate template = content.createTemplate(fw, fh);

Rectangle r = new Rectangle(0,0,fw, fw);
r.setBackgroundColor(BaseColor.YELLOW);
template.rectangle(r);

template.setFontAndSize(bf, 12);
template.beginText();
template.moveText(0, 0);
template.showText(text);
template.endText();

Image tmpImage = Image.getInstance(template);
tmpImage.setAbsolutePosition(Utilities.millimetersToPoints(x), Utilities.millimetersToPoints(pageHeight-(y+Utilities.pointsToMillimeters(fh))));
tmpImage.setRotationDegrees(0);
document.add(tmpImage);
Run Code Online (Sandbox Code Playgroud)

rotation itext

2
推荐指数
1
解决办法
5820
查看次数

标签 统计

itext ×1

rotation ×1