CaseLeaf

Handbook / The `table` command

The table command

The table you checked on screen has to become a spreadsheet.

Reads a table off a sheet and writes it out. You say which rectangle holds it, because a sheet often carries more than one and nothing in the file says where a table begins.

The reading works from where the words sit, so a row whose cells do not line up comes back short rather than padded, and the answer says how many such rows there were. tables is a different reading of the same sheet, the system's, by cell, useful as a second opinion rather than a preview of what this will produce.

How you run it

caseleaf table report.pdf --bounds 72,540,180,24

caseleaf table report.pdf --bounds 72,540,180,24 --page 1 --to file.csv|.tsv

What each part means

In full, every part it will take:

caseleaf table <file> --bounds x,y,w,h [--page <n>] [--to <file.csv|.tsv>]
part what it is for
<file> The PDF to work on, as a path, such as report.pdf beside you, or the full path to it. It is read and not written.
--bounds The rectangle, as four numbers: distance from the left, distance from the bottom, width, height, all in points, 72 to the inch. 72,540,180,24 is a box an inch in from the left, near the top of an A4 sheet. Commas, semicolons or spaces all separate them, and since a semicolon ends a command in most shells, that spelling wants quoting: --bounds "72;540;180;24".
--page Which sheet, counting from 1, so --page 4 is the fourth sheet as it sits in the file, whatever number is printed on it. Left out, the first sheet.
--to Where to write the table, as a path ending .csv or .tsv, for example schedule.csv. The extension chooses: .tsv separates with tabs, which is what you want when the cells themselves contain commas. Left out, the answer carries both spellings along with where the columns were found.

Printed as both TSV and CSV, or written to one of them. Rows holding fewer cells than the table has columns are reported rather than padded.

What comes back

Asked of a short sample document, it answers as below. The sample has eight sheets, a highlight and a note left by a reviewer, a web link, a small table, two pictures and one form field already filled in.

{
  "columns" : 1,
  "csv" : "ABAB",
  "edges" : [
    76
  ],
  "ragged" : [

  ],
  "rows" : 1,
  "tsv" : "ABAB"
}

The same thing from AppleScript

Everything above can be asked for from a script instead. There is one AppleScript command, perform: on names the document, and options takes the rest exactly as you would type it.

tell application "CaseLeaf"
    perform "table" on "/path/to/report.pdf" ¬
        options "--bounds 72,540,180,24"
end tell

tell application "CaseLeaf"
    perform "table" on "/path/to/report.pdf" ¬
        options "--bounds 72,540,180,24 --page 1 --to file.csv|.tsv"
end tell

All the commands · Asking from a script · Contents