Sample code for 30+ languages & platforms
Android™ Requires Chilkat v11.7.0+

Extract Right-to-Left (Hebrew, Arabic) Text in Logical Order

See more PDF Text Extraction Examples

Demonstrates the "bidi" clean-up option. PDFs draw right-to-left text in visual order (the order of the glyphs on the page); by default the extracted text is reordered into logical order, so that it reads and compares correctly. Set "bidi" to false to get the glyphs in the order they are drawn.

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    //  The PDF used in this example is available at hebrew_line.pdf

    CkPdf pdf = new CkPdf();
    success = pdf.LoadFile("qa_data/pdf/hebrew_line.pdf");
    if (success == false) {
        Log.i(TAG, pdf.lastErrorText());
        return;
        }

    CkJsonObject json = new CkJsonObject();
    CkJsonObject jsonOut = new CkJsonObject();

    //  The page has a line of Hebrew with a Latin word (PDF) and a number (2026) embedded in it.
    //  In logical order the line reads: kovetz PDF mishnat 2026 muchan ("the PDF file from 2026 is ready"),
    //  with the Hebrew words in reading order and "PDF" and "2026" kept left to right.
    success = pdf.ExtractText("text",json,jsonOut);
    if (success == false) {
        Log.i(TAG, pdf.lastErrorText());
        return;
        }

    Log.i(TAG, "---- default (bidi: true, logical order) ----");
    Log.i(TAG, jsonOut.stringOf("text"));

    //  Without reordering, the Hebrew words come out reversed and in the opposite order, as drawn.
    json.UpdateBool("bidi",false);
    success = pdf.ExtractText("text",json,jsonOut);
    if (success == false) {
        Log.i(TAG, pdf.lastErrorText());
        return;
        }

    Log.i(TAG, "---- bidi: false (as drawn) ----");
    Log.i(TAG, jsonOut.stringOf("text"));

    //  Sample output (the Hebrew is shown here transliterated):

    //  ---- default (bidi: true, logical order) ----
    //  Right-to-Left Text
    //  
    //  The line below is Hebrew with a Latin word and a number embedded in it:
    //  
    //  kovetz PDF mishnat 2026 muchan
    //  ---- bidi: false (as drawn) ----
    //  Right-to-Left Text
    //  
    //  The line below is Hebrew with a Latin word and a number embedded in it:
    //  
    //  nachum 2026 tanshim PDF ztevok    (the words in reverse order, each Hebrew word with its letters reversed)

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}