# Original example using the documented Docling Python API.
# Run in your own prepared environment beside the three practice PDFs.
from pathlib import Path
import argparse

parser = argparse.ArgumentParser(description="Convert the three original practice quotes, then review them against the PDFs.")
parser.add_argument("--artifacts-path", type=Path, help="Model directory prefetched with the installed Docling tools")
parser.add_argument("--output-dir", type=Path, default=Path("extracted-quotes"))
args = parser.parse_args()
sources = [Path(name) for name in ("quote-a.pdf", "quote-b.pdf", "quote-c.pdf")]
output = args.output_dir
for source in sources:
    if not source.is_file():
        raise FileNotFoundError(f"Missing practice PDF: {source}")
    target = output / (source.stem + ".md")
    if target.exists():
        raise FileExistsError(f"Keep your previous output or choose a new folder: {target}")
if args.artifacts_path and not args.artifacts_path.is_dir():
    raise FileNotFoundError(f"Missing model directory: {args.artifacts_path}")
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions

options = PdfPipelineOptions()
if args.artifacts_path:
    options.artifacts_path = str(args.artifacts_path.resolve())
converter = DocumentConverter(format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=options)})
output.mkdir(parents=True, exist_ok=True)
for source in sources:
    target = output / (source.stem + ".md")
    document = converter.convert(str(source)).document
    target.write_text(document.export_to_markdown(), encoding="utf-8")
print("Review the extracted Markdown against each source PDF before comparing quotes.")
