Does anyone have any idea how TabStop works?

I'm still trying to learn iText and have a few of the concepts down. However I can't figure out what TabStop is or how to use it. My particular problem is that I want to fill the end of all paragraphs with a bunch of dashes. I believe this is called a TabStop and I see the class in the iText API but I have no clue on how to use it.

Posted on StackOverflow on Mar 26, 2014 by Jesus Mireles

This is a short example that uses the TabStop in iText 7:

PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);

Paragraph p = new Paragraph("Hello World.");
doc.add(p);

p = new Paragraph();
p.addTabStops(new TabStop(56f, TabAlignment.LEFT));
p.add(new Tab());
p.add("Hello World with tab.");
doc.add(p);

p = new Paragraph();
p.addTabStops(new TabStop(56f, TabAlignment.LEFT));
p.add(new Text("Hello World with"));
p.add(new Tab());
p.add(new Text("an inline tab."));
doc.add(p);

doc.close();

Here is the result:

TabStops

TabStops

We use addTabStops() method to set TabStops and test them on the pieces of Text. Both of them have the position (width) of 56 user units and now, when we create Tabs inside or before text, they will make the “offset” equals to 56 user units.

You can learn more about Tab Stop on the Wikipedia.

Click this link if you want to see how to answer this question in iText 5.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now