A Forms tab on each person fills in TM.7, STM.2, STM.9, STM.11 and STM.1 for an extension of stay, TM.47 for a 90-day report and TM.8 for a re-entry permit. The Bureau's blank pages (forms/, with their sources and checksums) go unchanged into a new PDF, and the values are written on the dotted lines in Sarabun; boxes are ticked and the title circled where a form asks. scripts/gen_layout.py measures the blanks into src/papers/layout.rs. The tab says what would stay blank and links to where it is added. What only the application says (the date, the office, the reason, the days, a trip) is carried in the links and never stored. The extension's five forms also come in one PDF. Opening or downloading a form is audited as entity "form" with the forms' codes, never their values. Migration 0005 adds what STM.1 and STM.11 ask of the company (capital, revenue, equity, staff, a coordinator), a work permit's salary and contract dates, and where an arrival came from. The Nix package now takes forms/.
50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
"""List the blanks of an official form: the runs of dots (or the ellipsis
|
|
character) that the applicant writes on, with their page, position and the
|
|
label before them. Positions are PDF points from the top left of the page,
|
|
the system krilla draws in, so a value starts at x0 on the baseline.
|
|
|
|
uv run --with pymupdf python scripts/form_blanks.py forms/tm7.pdf
|
|
|
|
Used to measure a form's blanks for src/forms/layout.rs when a form is new
|
|
or the Immigration Bureau publishes a new version of it.
|
|
"""
|
|
|
|
import sys
|
|
|
|
import pymupdf
|
|
|
|
DOTS = {".", "\u2026", "\u00b7"}
|
|
|
|
|
|
def blanks(path):
|
|
doc = pymupdf.open(path)
|
|
for pno, page in enumerate(doc):
|
|
raw = page.get_text("rawdict")
|
|
for block in raw["blocks"]:
|
|
for line in block.get("lines", []):
|
|
chars = [c for span in line["spans"] for c in span["chars"]]
|
|
origin_y = None
|
|
i = 0
|
|
while i < len(chars):
|
|
if chars[i]["c"] in DOTS:
|
|
j = i
|
|
while j < len(chars) and chars[j]["c"] in DOTS:
|
|
j += 1
|
|
if j - i >= 4:
|
|
label = "".join(c["c"] for c in chars[max(0, i - 28) : i])
|
|
x0 = chars[i]["bbox"][0]
|
|
x1 = chars[j - 1]["bbox"][2]
|
|
origin_y = chars[i]["origin"][1]
|
|
yield pno + 1, round(x0, 1), round(x1, 1), round(origin_y, 1), label.strip()
|
|
i = j
|
|
else:
|
|
i += 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for path in sys.argv[1:]:
|
|
print(f"== {path}")
|
|
rows = sorted(blanks(path), key=lambda r: (r[0], r[3], r[1]))
|
|
for n, (page, x0, x1, y, label) in enumerate(rows, 1):
|
|
print(f"{n:3} p{page} x {x0:6.1f}..{x1:6.1f} (w {x1 - x0:5.1f}) y {y:6.1f} after {label!r}")
|