Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.7.0+

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loSb
LOCAL loJsonOut

lnSuccess = 0

*  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

loPdf = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf.LoadFile("qa_data/pdf/warehouse_inventory.pdf")
IF (lnSuccess = 0) THEN
    ? loPdf.LastErrorText
    RELEASE loPdf
    CANCEL
ENDIF

loJson = CreateObject('Chilkat.JsonObject')
loSb = CreateObject('Chilkat.StringBuilder')
loJsonOut = CreateObject('Chilkat.JsonObject')

*  ---- 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.
loJson.UpdateString("layout","flow")
lnSuccess = loPdf.ExtractTextSb("text",loJson,loSb,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf.LastErrorText
    RELEASE loPdf
    RELEASE loJson
    RELEASE loSb
    RELEASE loJsonOut
    CANCEL
ENDIF

? "---- flow ----"
? loSb.GetAsString()

*  ---- lines ----
*  Each visual line of the page is one output line.  A table row is its cells joined by single spaces.
loJson.UpdateString("layout","lines")
loSb.Clear()
lnSuccess = loPdf.ExtractTextSb("text",loJson,loSb,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf.LastErrorText
    RELEASE loPdf
    RELEASE loJson
    RELEASE loSb
    RELEASE loJsonOut
    CANCEL
ENDIF

? "---- lines ----"
? loSb.GetAsString()

*  ---- 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.
loJson.UpdateString("layout","grid")
loSb.Clear()
lnSuccess = loPdf.ExtractTextSb("text",loJson,loSb,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf.LastErrorText
    RELEASE loPdf
    RELEASE loJson
    RELEASE loSb
    RELEASE loJsonOut
    CANCEL
ENDIF

? "---- grid ----"
? loSb.GetAsString()

*  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.

RELEASE loPdf
RELEASE loJson
RELEASE loSb
RELEASE loJsonOut