title: pdfbox 2 - how to write from right to left
body: <p>I'm using pdfbox version 2-RC3</p>
  <p>Was able to use unicode. the probelm is that the text I'm getting on the pdf is from left to right.
  I need to write Hebrew from right to left.
  How do I do it?</p>
  <pre><code>package pdfProj.test;
  
  import java.io.File;
  
  import org.apache.pdfbox.pdmodel.PDDocument;
  import org.apache.pdfbox.pdmodel.PDPage;
  import org.apache.pdfbox.pdmodel.PDPageContentStream;
  import org.apache.pdfbox.pdmodel.common.PDRectangle;
  import org.apache.pdfbox.pdmodel.font.PDType0Font;
  
  public class utftext {
  
      public static void main(String[] args) throws Exception {
          PDDocument document = new PDDocument();
          PDPage page = new PDPage(PDRectangle.A4);
          document.addPage(page);
          File tnrFontFile = new File(&quot;c://temp//font//times.ttf&quot;);
          PDType0Font font = PDType0Font.load(document, tnrFontFile);
          PDPageContentStream stream = new PDPageContentStream(document, page);
          String text = &quot;Hello how r u?  שלום מה שלןמך&quot;;
          stream.beginText();
          stream.setFont(font, 12);
          stream.moveTextPositionByAmount(50, 600);
          stream.drawString(text);
          stream.endText();
          stream.close();
          document.save(&quot;c://temp//pdf//type0_1.pdf&quot;);
          document.close();
      }
  }
  </code></pre>
  <p>the output is:</p>
  <p><a href="https://i.stack.imgur.com/MEf7N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MEf7N.png" alt="enter image description here" /></a></p>
  <p>Ended up with this:</p>
  <pre><code>    public static String getStrAccordingToLocal(String str)
  {
      StringBuilder value = new StringBuilder(str);
      
      if (CommonUtil.notEmpty(str) &amp;&amp; PdfUtil.isEnglishAsccii(str.charAt(0)))
      {
          return str;
      }
      value.reverse();
      
      return value.toString();
  }
  </code></pre>