#!/usr/bin/env python3
"""Render a clipped region of the RT-4D schematic PDF at high DPI.
  python schem.py <x0> <y0> <x1> <y1> <dpi> <out.png>     (coords in PDF points)
Sheets (approx, points):  1: y 12-582 | 2: y 600-1170 | 3: y 1200-1764 | 4: y 1794-2370
Page is 864 x 2400 pt.
"""
import sys, fitz

PDF = "/mnt/c/Users/vikto/Downloads/Telegram Desktop/RT4DDLT01.pdf"

def render(x0, y0, x1, y1, dpi, out):
    doc = fitz.open(PDF)
    p = doc[0]
    clip = fitz.Rect(x0, y0, x1, y1)
    pm = p.get_pixmap(dpi=dpi, clip=clip)
    pm.save(out)
    print(f"{out}: {pm.width}x{pm.height}  clip=({x0},{y0})-({x1},{y1}) dpi={dpi}")

if __name__ == "__main__":
    a = sys.argv[1:]
    render(float(a[0]), float(a[1]), float(a[2]), float(a[3]), int(a[4]), a[5])
