DataFlex Requires Chilkat v11.7.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPdf
Variant vJson
Handle hoJson
Variant vJsonOut
Handle hoJsonOut
String sTemp1
Move False To iSuccess
// 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
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get ComLoadFile Of hoPdf "qa_data/pdf/hebrew_line.pdf" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
// 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.
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractText Of hoPdf "text" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- default (bidi: true, logical order) ----"
Get ComStringOf Of hoJsonOut "text" To sTemp1
Showln sTemp1
// Without reordering, the Hebrew words come out reversed and in the opposite order, as drawn.
Get ComUpdateBool Of hoJson "bidi" False To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractText Of hoPdf "text" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- bidi: false (as drawn) ----"
Get ComStringOf Of hoJsonOut "text" To sTemp1
Showln sTemp1
// 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)
End_Procedure