| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import argparse | |
| import csv | |
| from pathlib import Path | |
| import img2pdf | |
| SOURCE_ROOT = Path("/workspace/SchemID/derived/Source") | |
| SHEETS_ROOT = SOURCE_ROOT / "sheets" | |
| FIXED_DPI = (300, 300) | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument( | |
| "--manifest", | |
| type=Path, | |
| default=SHEETS_ROOT / "sheet_manifest.csv", | |
| help="Sheet manifest CSV path.", | |
| ) | |
| parser.add_argument( | |
| "--output-pdf", | |
| type=Path, | |
| default=SHEETS_ROOT / "all_visualization_sheets.pdf", | |
| help="Output PDF path.", | |
| ) | |
| args = parser.parse_args() | |
| image_paths: list[str] = [] | |
| with args.manifest.open(newline="") as handle: | |
| reader = csv.DictReader(handle) | |
| for row in reader: | |
| image_path = SHEETS_ROOT / row["sheet_png"] | |
| image_paths.append(str(image_path)) | |
| layout_fun = img2pdf.get_fixed_dpi_layout_fun(FIXED_DPI) | |
| args.output_pdf.parent.mkdir(parents=True, exist_ok=True) | |
| with args.output_pdf.open("wb") as handle: | |
| handle.write(img2pdf.convert(image_paths, layout_fun=layout_fun)) | |
| if __name__ == "__main__": | |
| main() | |