DataFlex Requires Chilkat v11.7.0+
DataFlex
Extract Text from a Two-Column PDF
See more PDF Text Extraction Examples
Demonstrates how multi-column pages are read. By default the columns are detected and each column is read top to bottom before the next ("columns": "auto"); "columns": "none" reads the full page width line by line, which interleaves the columns. The quality report tells how many columns were found.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPdf
Variant vJson
Handle hoJson
Variant vJsonOut
Handle hoJsonOut
String sTemp1
Integer iTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The two-column PDF used in this example is available at two_column_article.pdf
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get ComLoadFile Of hoPdf "qa_data/pdf/two_column_article.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
// With the default options the columns are detected, and the text of the left column
// comes before the text of the right column.
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
Get ComIntOf Of hoJsonOut "quality.pages[0].columns" To iTemp1
Showln "Columns detected: " iTemp1
Get ComStringOf Of hoJsonOut "quality.pages[0].readingOrderSource" To sTemp1
Showln "Reading order: " sTemp1
Get ComStringOf Of hoJsonOut "text" To sTemp1
Showln sTemp1
// "none" switches column detection off: the page is read across its full width, line by line,
// so each output line holds a line of the left column followed by a line of the right column.
// This is rarely wanted, but it shows what the detection does.
Get ComUpdateString Of hoJson "columns" "none" To iSuccess
Get ComUpdateString Of hoJson "layout" "lines" 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 "---- columns: none ----"
Get ComStringOf Of hoJsonOut "text" To sTemp1
Showln sTemp1
// Sample output (abbreviated):
// Columns detected: 2
// Reading order: visual
// The Harbor Lighthouse, Season Two
//
// The harbor lighthouse was built in 1874 to mark the entrance to the inner channel. It operated continuously until 1968, ...
//
// The restoration society took ownership in 2021 with three goals: ...
// ...
// The lantern room frame was stripped, primed and repainted in the original dark green. ...
// ...
// ---- columns: none ----
// The Harbor Lighthouse, Season Two
// The harbor lighthouse was built in 1874 to The lantern room frame was stripped, primed
// mark the entrance to the inner channel. It and repainted in the original dark green. New
// ...
End_Procedure