- ocr/: Tesseract-based vendor/date/total extraction. PSM 6 (single uniform text block) instead of the default fixes receipts where item-name/price columns were otherwise split into separate blocks and dropped. Vendor line picked by median (not max) word height within the top fraction of the crop, breaking ties by topmost line - max() was fooled by single descender/ascender glyphs (commas, parens) inflating one word's bounding box. - naming/: merge OCR metadata into YYYY-MM-DD_vendor.pdf filenames, degrading gracefully to UNSORTED_<timestamp>.pdf; per-run dedup. - pdf/: img2pdf-based multi-page-capable assembly (images_to_pdf). - pipeline.run_export(): OCR + name + PDF each detected crop from a detect() report, writes pdf/ and export_summary.csv. - New `paperpod export <video>` CLI command. - Verified against synthetic Home Depot/Metro/Petro-Canada receipts: 3/3 correct vendor, date, and total after tuning. Known limitation (documented in README): no page-flip/multi-page grouping yet (that's events/, still unbuilt) - every detected document becomes its own single-page PDF.
32 lines
861 B
Python
32 lines
861 B
Python
"""Assemble one or more page images into a single PDF (img2pdf)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import img2pdf
|
|
|
|
|
|
def images_to_pdf(
|
|
image_paths: list[str | Path],
|
|
out_path: str | Path,
|
|
title: str | None = None,
|
|
) -> Path:
|
|
"""Combine images (in order) into a single multi-page PDF.
|
|
|
|
img2pdf embeds the source images losslessly (no re-encoding/quality
|
|
loss) rather than rasterizing through a rendering step.
|
|
"""
|
|
if not image_paths:
|
|
raise ValueError("images_to_pdf requires at least one image")
|
|
out_path = Path(out_path)
|
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
kwargs = {}
|
|
if title:
|
|
kwargs["title"] = title.encode("utf-8")
|
|
|
|
pdf_bytes = img2pdf.convert([str(p) for p in image_paths], **kwargs)
|
|
out_path.write_bytes(pdf_bytes)
|
|
return out_path
|