Rendering text from right to left : Chunk Rendering Mode « PDF RTF « Java






Rendering text from right to left

Rendering text from right to left
import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class RightToLeftPDF {
  public static void main(String[] args) {
    try {
      Document document = new Document(PageSize.A4, 50, 50, 50, 50);
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("RightToLeftPDF.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();

      ColumnText ct = new ColumnText(cb);
      ct.setSimpleColumn(100, 100, 500, 800, 24, Element.ALIGN_LEFT);
      ct.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
      ct.setLeading(0, 1);
      ct.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
      ct.setAlignment(Element.ALIGN_CENTER);
      ct.addText(new Chunk("ABCD"));
      ct.go();
      ct.setAlignment(Element.ALIGN_JUSTIFIED);
      ct.addText(new Chunk("ABCD"));
      ct.go();
      ct.setAlignment(Element.ALIGN_CENTER);
      ct.addText(new Chunk("ABCD"));
      ct.go();

      document.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
           
       








itext.zip( 1,748 k)

Related examples in the same category

1.Rendering Mode: TEXT_RENDER_MODE_FILL
2.Rendering Mode: TEXT_RENDER_MODE_FILL_STROKE, width 0.5f
3.Rendering Mode: TEXT_RENDER_MODE_FILL_STROKE
4.Rendering Mode: TEXT_RENDER_MODE_INVISIBLE
5.Rendering Mode: TEXT_RENDER_MODE_STROKE