Tcl Requires Chilkat v11.7.0+
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 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
set pdf [new_CkPdf]
set success [CkPdf_LoadFile $pdf "qa_data/pdf/warehouse_inventory.pdf"]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
exit
}
set json [new_CkJsonObject]
set sb [new_CkStringBuilder]
set jsonOut [new_CkJsonObject]
# ---- 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.
CkJsonObject_UpdateString $json "layout" "flow"
set success [CkPdf_ExtractTextSb $pdf "text" $json $sb $jsonOut]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkStringBuilder $sb
delete_CkJsonObject $jsonOut
exit
}
puts "---- flow ----"
puts [CkStringBuilder_getAsString $sb]
# ---- lines ----
# Each visual line of the page is one output line. A table row is its cells joined by single spaces.
CkJsonObject_UpdateString $json "layout" "lines"
CkStringBuilder_Clear $sb
set success [CkPdf_ExtractTextSb $pdf "text" $json $sb $jsonOut]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkStringBuilder $sb
delete_CkJsonObject $jsonOut
exit
}
puts "---- lines ----"
puts [CkStringBuilder_getAsString $sb]
# ---- 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.
CkJsonObject_UpdateString $json "layout" "grid"
CkStringBuilder_Clear $sb
set success [CkPdf_ExtractTextSb $pdf "text" $json $sb $jsonOut]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkStringBuilder $sb
delete_CkJsonObject $jsonOut
exit
}
puts "---- grid ----"
puts [CkStringBuilder_getAsString $sb]
# 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.
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkStringBuilder $sb
delete_CkJsonObject $jsonOut