简体   繁体   中英

Align text on two different lines using iText

I'm creating a PDF using iText and want to vertically align text in two paragraphs. I'm using tab characters to try and align the "1" and the "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.

Search the PDF for TAB CHUNKS . Note that the '\\t' character has no meaning in a PDF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM