PDFBox PDPageContentstream.setTextMatrix() 使文本消失
我正在将 POSPrint 数据转换为 PDF。在某一点上,我需要将文本拉伸超过 2 行,但宽度与普通文本相同。我正在尝试像这样存档:
CONTENT.beginText();
Matrix textMatrix = new Matrix();
textMatrix.scale(1f, 2f);
CONTENT.setTextMatrix(textMatrix);
CONTENT.newLineAtOffset(50, 50);
CONTENT.setCharacterSpacing(line.getLineSpacing());
CONTENT.showText(restOfLine);
CONTENT.endText();
遗憾的是,这导致文本根本不显示。如果我删除用于添加文本矩阵的行,或将矩阵比例值设置为 1,则不会出现任何问题:
CONTENT.beginText();
Matrix textMatrix = new Matrix();
textMatrix.scale(1f, 1f);
CONTENT.setTextMatrix(textMatrix);
CONTENT.newLineAtOffset(50, 50);
CONTENT.setCharacterSpacing(line.getLineSpacing());
CONTENT.showText(restOfLine);
CONTENT.endText();
或者
CONTENT.beginText();
CONTENT.newLineAtOffset(50, 50);
CONTENT.setCharacterSpacing(line.getLineSpacing());
CONTENT.showText(restOfLine);
CONTENT.endText();
有人知道为什么会发生这种情况吗?
我使用PDFBox 2.0.25
I am converting POSPrint-data to a PDF. At one Point i need to strech the Text over 2 Lines, but with the width of the normal text. I'm trying to archive that like this:
CONTENT.beginText();
Matrix textMatrix = new Matrix();
textMatrix.scale(1f, 2f);
CONTENT.setTextMatrix(textMatrix);
CONTENT.newLineAtOffset(50, 50);
CONTENT.setCharacterSpacing(line.getLineSpacing());
CONTENT.showText(restOfLine);
CONTENT.endText();
sadly this results in the text not showing up at all. If i remove the lines for adding the textmatrix, or setting the matrix scale values to 1 this workes without any problem:
CONTENT.beginText();
Matrix textMatrix = new Matrix();
textMatrix.scale(1f, 1f);
CONTENT.setTextMatrix(textMatrix);
CONTENT.newLineAtOffset(50, 50);
CONTENT.setCharacterSpacing(line.getLineSpacing());
CONTENT.showText(restOfLine);
CONTENT.endText();
or
CONTENT.beginText();
CONTENT.newLineAtOffset(50, 50);
CONTENT.setCharacterSpacing(line.getLineSpacing());
CONTENT.showText(restOfLine);
CONTENT.endText();
Does anybody know why this happens?
I use PDFBox 2.0.25
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果缩放 TextMatrix,矩阵的位置也会受到影响。要解决移动缩放文本的这种不需要的行为,您还必须将文本位置除以比例。
If you are scaling the TextMatrix, also the position of the matrix is affected. To fix this unwanted behavior of moving the scaled text, you have to divide the textposition also by the scale.