DataFlex Requires Chilkat v11.7.0+
DataFlex
PDF Text Layouts: flow, lines and grid
See more PDF Text Extraction Examples
Demonstrates the "layout" option of the "text" operation. "flow" (the default) joins the lines of each paragraph and returns tables as tab-separated rows; "lines" keeps each visual line of the page on its own line; "grid" pads with spaces so that the horizontal positions are preserved, like a fixed-pitch rendering of the page.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPdf
Variant vJson
Handle hoJson
Variant vSb
Handle hoSb
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 (a title, a paragraph, and a table with ruled cells) is available at warehouse_inventory.pdf
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get ComLoadFile Of hoPdf "qa_data/pdf/warehouse_inventory.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(cComChilkatStringBuilder)) To hoSb
If (Not(IsComObjectCreated(hoSb))) Begin
Send CreateComObject of hoSb
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
// ---- flow (the default) ----
// The lines of a paragraph are joined into one line. A table becomes one line per row
// with the cells separated by tabs, followed by a blank line.
Get ComUpdateString Of hoJson "layout" "flow" To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoSb to vSb
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractTextSb Of hoPdf "text" vJson vSb vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- flow ----"
Get ComGetAsString Of hoSb To sTemp1
Showln sTemp1
// ---- lines ----
// Each visual line of the page is one output line. A table row is its cells joined by single spaces.
Get ComUpdateString Of hoJson "layout" "lines" To iSuccess
Send ComClear To hoSb
Get pvComObject of hoJson to vJson
Get pvComObject of hoSb to vSb
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractTextSb Of hoPdf "text" vJson vSb vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- lines ----"
Get ComGetAsString Of hoSb To sTemp1
Showln sTemp1
// ---- grid ----
// Each line is padded with spaces so that the text sits at its horizontal position on the page.
// Table columns line up as they do on the page, which suits fixed-width parsing.
Get ComUpdateString Of hoJson "layout" "grid" To iSuccess
Send ComClear To hoSb
Get pvComObject of hoJson to vJson
Get pvComObject of hoSb to vSb
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractTextSb Of hoPdf "text" vJson vSb vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- grid ----"
Get ComGetAsString Of hoSb To sTemp1
Showln sTemp1
// Sample output (abbreviated; the tabs in the flow output are shown as -> here):
// ---- flow ----
// Warehouse Inventory Report
//
// Stock on hand at the Wheaton distribution center as of September 30, 2026. Quantities are counted units; the unit cost is the average landed cost in US dollars. Items at or below their reorder point are flagged in the status column.
//
// SKU->Description->Category->Qty on Hand->Unit Cost->Status
// WH-1001->Steel shelving unit, 5 tier->Storage->42->189.50->OK
// WH-1002->Pallet jack, 5500 lb->Equipment->7->412.00->Reorder
// WH-1003->Stretch wrap, 18 in roll->Packaging->640->9.75->OK
// ...
// WH-1012->Wire shelf liner, 48 in->Storage->24->6.15->Reorder
//
// Four items are at or below their reorder point and one item is out of stock. Purchase orders for the flagged items should be raised before the October cycle count.
//
// ---- lines ----
// Warehouse Inventory Report
// Stock on hand at the Wheaton distribution center as of September 30, 2026. Quantities are counted units; the
// unit cost is the average landed cost in US dollars. Items at or below their reorder point are flagged in the status
// column.
// SKU Description Category Qty on Hand Unit Cost Status
// WH-1001 Steel shelving unit, 5 tier Storage 42 189.50 OK
// WH-1002 Pallet jack, 5500 lb Equipment 7 412.00 Reorder
// WH-1003 Stretch wrap, 18 in roll Packaging 640 9.75 OK
// ...
// WH-1012 Wire shelf liner, 48 in Storage 24 6.15 Reorder
// Four items are at or below their reorder point and one item is out of stock. Purchase orders for the flagged items
// should be raised before the October cycle count.
//
// ---- grid ----
// Warehouse Inventory Report
// Stock on hand at the Wheaton distribution center as of September 30, 2026. Quantities are counted units; the
// unit cost is the average landed cost in US dollars. Items at or below their reorder point are flagged in the status
// column.
//
// SKU Description Category Qty on Hand Unit Cost Status
// WH-1001 Steel shelving unit, 5 tier Storage 42 189.50 OK
// WH-1002 Pallet jack, 5500 lb Equipment 7 412.00 Reorder
// WH-1003 Stretch wrap, 18 in roll Packaging 640 9.75 OK
// ...
// WH-1012 Wire shelf liner, 48 in Storage 24 6.15 Reorder
//
// Four items are at or below their reorder point and one item is out of stock. Purchase orders for the flagged items
// should be raised before the October cycle count.
End_Procedure