Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java PDF: Ecrire les textes de droite à gauche

Java PDF: Ecrire les textes de droite à gauche
{filelink=10362}

/***** Code de MesExemples.com *******/
/**
 * @(#)ExempleRightToLeftPDF.java
 *
 *
 * @author 
 *sakoba(java.mesexemples.com) @version 1.00 2013/4/26
 */
 
 
 
import java.io.FileOutputStream;
 
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;
 
public class ExempleRightToLeftPDF {
  public static void main(String[] args) {
    try {
      Document document = new Document(PageSize.A4, 50, 50, 50, 50);
      PdfWriter pdf_writer = PdfWriter.getInstance(document, 
      	new FileOutputStream("c:/ExRightToLeftPDF.pdf"));
      pdf_writer.setPdfVersion(pdf_writer.PDF_VERSION_1_7);
      document.open();
      PdfContentByte cb = pdf_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("إرسال "));
      ct.go();
      ct.setAlignment(Element.ALIGN_JUSTIFIED);
      ct.addText(new Chunk("ABCD"));
      ct.go();
      ct.setAlignment(Element.ALIGN_CENTER);
      ct.addText(new Chunk("إرسال"));
      ct.go();
 
      document.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}