[英]Align text on two different lines using iText
I'm creating a PDF using iText and want to vertically align text in two paragraphs. 我正在使用iText创建PDF,并希望在两个段落中垂直对齐文本。 I'm using tab characters to try and align the "1" and the "2":
我使用制表符尝试将“ 1”和“ 2”对齐:
document.add(new Paragraph("Example"+"\t\t\t1"));
document.add(new Phrase("Hello World JAVA"+"\t\t\t2"));
Here is a screenshot of how the resulting PDF looks: 这是生成的PDF外观的屏幕截图:
Can anyone suggest a better way to align text? 谁能建议一种更好的文本对齐方式? Clearly tabs are not working how I expected.
显然,选项卡无法正常工作。 What I'm looking for is this:
我正在寻找的是:
Example 1
Hello World JAVA 2
I just discovered how to upvote comments, and I upvoted mkl's remark because the answer can indeed by found in http://www.manning.com/lowagie2/samplechapter2.pdf of which I'm the author. 我刚刚发现了如何对评论进行投票,并且我对mkl的评论也投了赞成票,因为答案的确可以在我是作者的http://www.manning.com/lowagie2/samplechapter2.pdf中找到。
Search the PDF for TAB CHUNKS . 在PDF中搜索TAB CHUNKS 。 Note that the
'\\t'
character has no meaning in a PDF. 请注意,在PDF中,
'\\t'
字符没有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.