Tabbing examples

This is a code example of iText PDF, discover more.

25th October 2015
admin-marketing

Switch code for this example

Tabs.java
  1. /**
  2.  * Example written by Michaël Demey to demonstrate the use of the new Tab functionality.
  3.  *
  4.  * The code adds three paragraphs:
  5.  * 1. Without a tab
  6.  * 2. With a leading tab
  7.  * 3. With an inline tab
  8.  */
  9. package sandbox.objects;
  10.  
  11. import com.itextpdf.text.Chunk;
  12. import com.itextpdf.text.Document;
  13. import com.itextpdf.text.DocumentException;
  14. import com.itextpdf.text.Paragraph;
  15. import com.itextpdf.text.TabSettings;
  16. import com.itextpdf.text.pdf.PdfWriter;
  17.  
  18. import java.io.File;
  19. import java.io.FileNotFoundException;
  20. import java.io.FileOutputStream;
  21. import java.io.IOException;
  22.  
  23. import sandbox.WrapToTest;
  24.  
  25. @WrapToTest
  26. public class Tabs {
  27.  
  28.     public static final String DEST = "results/objects/tabs.pdf";
  29.  
  30.     public static void main(String[] args) throws IOException, DocumentException {
  31.         File file = new File(DEST);
  32.         file.getParentFile().mkdirs();
  33.         new Tabs().createPdf(DEST);
  34.     }
  35.  
  36.     public void createPdf(String dest) throws FileNotFoundException, DocumentException {
  37.         Document document = new Document();
  38.  
  39.         PdfWriter.getInstance(document, new FileOutputStream(dest));
  40.  
  41.         document.open();
  42.  
  43.         Paragraph p = new Paragraph("Hello World.");
  44.  
  45.         document.add(p);
  46.  
  47.         p = new Paragraph();
  48.         p.setTabSettings(new TabSettings(56f));
  49.         p.add(Chunk.TABBING);
  50.         p.add(new Chunk("Hello World with tab."));
  51.  
  52.         document.add(p);
  53.  
  54.         p = new Paragraph();
  55.         p.add(new Chunk("Hello World with"));
  56.         p.setTabSettings(new TabSettings(56f));
  57.         p.add(Chunk.TABBING);
  58.         p.add(new Chunk("an inline tab."));
  59.  
  60.         document.add(p);
  61.  
  62.         document.close();
  63.     }
  64.  
  65. }
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