Text alignment: Right Left : PdfContentByte « PDF RTF « Java






Text alignment: Right Left

Text alignment: Right Left
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

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

      cb.beginText();

      BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
      cb.setFontAndSize(bf, 12);

      cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, " Right", 250, 350, 0);
      cb.showTextAligned(PdfContentByte.ALIGN_LEFT, " Left", 250, 300, 0);

      cb.endText();
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}

           
       








itext.zip( 1,748 k)

Related examples in the same category

1.Drawing text using PdfContentByteDrawing text using PdfContentByte
2.Setting Color for PdfContentByteSetting Color for PdfContentByte
3.Closing StrokeClosing Stroke
4.PdfContentByte: RGBColorStrokeFPdfContentByte: RGBColorStrokeF
5.Stroke Line WidthStroke Line Width