CaseLeaf

Handbook / The `writefields` command

The writefields command

A form has to match a specification somebody else wrote, field for field, and automatic detection puts them in the wrong places.

Writes form fields in from a description you give, rather than from what the application detected. It is the escape hatch for makeform: when detection is wrong, or the layout is unusual, or the fields have to match a specification somebody else wrote, this puts them exactly where you say.

How you run it

caseleaf writefields report.pdf --to reviewed.pdf --spec fields.json

What each part means

In full, every part it will take:

caseleaf writefields <file> --to <output> --spec <fields.json>
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.
--to Where to write the result, as a path. The shape above shows which format this command writes. This command needs it, and writes only there: the document you named is left exactly as it was.
--spec The fields to write, as a path to a JSON file, for example fields.json. Inside is a plain array of rows, each with x, y, width, height and a kind: text, textarea, checkbox, comb, radio, choice, listbox or signature. fields prints those rows, but wrapped in an answer alongside a count. Hand that over whole and this says there are no fields in the file. Take the array out first.

The rows fields prints, so a set can be read out, corrected and written back the way the window does it: the array on its own, not the answer that carries it.

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.

{
  "fields" : 2,
  "written" : true
}

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 "writefields" on "/path/to/report.pdf" ¬
        options "--to reviewed.pdf --spec fields.json"
end tell

All the commands · Asking from a script · Contents