Vertical text

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

8th November 2015
admin-marketing

Switch code for this example

VTExample.java
  1. /**
  2.  * This code sample was written by Bruno Lowagie in answer to this question:
  3.  * http://stackoverflow.com/questions/28564434/why-i-cant-vertically-print-this-string-with-itext
  4.  */
  5. package sandbox.objects;
  6.  
  7. import com.itextpdf.text.Document;
  8. import com.itextpdf.text.DocumentException;
  9. import com.itextpdf.text.Font;
  10. import com.itextpdf.text.Phrase;
  11. import com.itextpdf.text.pdf.BaseFont;
  12. import com.itextpdf.text.pdf.PdfWriter;
  13. import com.itextpdf.text.pdf.VerticalText;
  14.  
  15. import java.io.File;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import sandbox.WrapToTest;
  19.  
  20. @WrapToTest
  21. public class VTExample {
  22.  
  23.     public static final String DEST = "results/objects/vertical_text.pdf";
  24.     public static final String FONT = "resources/fonts/FreeSans.ttf";
  25.    
  26.     public static void main(String[] args) throws IOException, DocumentException {
  27.         File file = new File(DEST);
  28.         file.getParentFile().mkdirs();
  29.         new VTExample().createPdf(DEST);
  30.     }
  31.     public void createPdf(String dest) throws IOException, DocumentException {
  32.         Document document = new Document();
  33.         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
  34.         document.open();
  35.         BaseFont bf = BaseFont.createFont(
  36.             FONT, BaseFont.IDENTITY_V, BaseFont.NOT_EMBEDDED);
  37.         Font font = new Font(bf, 20);
  38.         VerticalText vt = new VerticalText(writer.getDirectContent());
  39.         vt.setVerticalLayout(559, 806, 770, 29, 18);
  40.         vt.addText(new Phrase("Hello World !!!", font));
  41.         vt.go();
  42.         document.close();
  43.     }
  44. }
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