python3 - <<'PY'
from pathlib import Path
from PIL import Image
from reportlab.pdfgen import canvas
from reportlab.lib.utils import ImageReader

pages = sorted(Path("/tmp/casino-pages").glob("page-*.png"))
if not pages:
    raise SystemExit("No page images were created.")

output = "Lab3_Casino_raster.pdf"
pdf = canvas.Canvas(output, pdfVersion=(1, 2), pageCompression=0)

for filename in pages:
    with Image.open(filename) as im:
        width, height = im.size
    page_width = width * 72 / 150
    page_height = height * 72 / 150
    pdf.setPageSize((page_width, page_height))
    pdf.drawImage(
        ImageReader(str(filename)),
        0, 0, width=page_width, height=page_height
    )
    pdf.showPage()

pdf.save()
print(f"Created {output} with {len(pages)} pages")
PY
