main
John Lauer Component record for rc0402fr-0740k2l: files batch 1 d2f2fb3 2d ago
"""Render the datasheet pages this page cites and crop the cited figures/tables.

usage: figures.py <rc-datasheet.pdf> <mounting.pdf> <outdir>
Boxes are in 100 dpi page pixels; pages are rendered at 150 dpi with pdftoppm.
"""
import sys, os, subprocess, tempfile, json, hashlib
from PIL import Image
ds, mount, out = sys.argv[1:4]
os.makedirs(out, exist_ok=True)
CROPS = [
    (ds, 2, (300, 160, 770, 1010), "rc-p2-ordering.png", "p.2 ordering information: global part number fields"),
    (ds, 3, (60, 155, 770, 292), "rc-p3-marking.png", "p.3 marking: RC0402 'No Marking' (Fig. 1)"),
    (ds, 4, (60, 150, 770, 760), "rc-p4-dimensions.png", "p.4 construction, Fig. 9 outline and Table 1 dimensions"),
    (ds, 5, (60, 160, 770, 560), "rc-p5-electrical.png", "p.5 Table 2 electrical characteristics, RC0402 rows"),
    (ds, 7, (60, 120, 770, 1085), "rc-p7-packing-power.png", "p.7 Table 4 packing, power rating, derating curve, rated voltage formula"),
    (mount, 4, (60, 160, 770, 800), "mount-p4-land.png", "Mounting V.10 p.4 Fig. 4 and Table 1 reflow footprint dimensions"),
]
idx = []
with tempfile.TemporaryDirectory() as td:
    for pdf, pg, box, name, what in CROPS:
        base = os.path.join(td, f"p{pg}-{os.path.basename(pdf)}")
        subprocess.run(["pdftoppm", "-r", "150", "-png", "-f", str(pg), "-l", str(pg), "-singlefile", pdf, base], check=True)
        im = Image.open(base + ".png").convert("RGB")
        im.crop(tuple(int(v * 1.5) for v in box)).save(os.path.join(out, name), optimize=True)
        idx.append({"file": name, "pdf": os.path.basename(pdf), "page": pg, "box_100dpi": box, "what": what,
                    "pdf_sha256": hashlib.sha256(open(pdf, "rb").read()).hexdigest()})
json.dump(idx, open(os.path.join(out, "figures.json"), "w"), indent=1)
print("figures", len(idx))