Combine all the images and PDF and make date-wise PDF in one pdf file.
cd /home/daytona/workspace/attachments/c7f871f6-a1e2-4417-87aa-84d40ab188cd && python3 -c " import pdfplumber for f in ['60502401284.pdf','60502400444.pdf','60502402198.pdf']: print(f'=== {f} ===') with pdfplumber.open(f) as pdf: for i, page in enumerate(pdf.pages[:2]): print(page.extract_text()[:500]) print('---') "
mkdir -p /home/daytona/workspace/medical-bills && cd /home/daytona/workspace/medical-bills && \ wget -q "https://d361swluvexzqs.cloudfront.net/chats-attachments/IMG_0003-1778921977274-6pcjj2.jpeg" -O img_gips_pharmacy_14may.jpeg && \ wget -q "https://d361swluvexzqs.cloudfront.net/chats-attachments/fcadff28-4fb0-4f2a-807c-b6e3fe5eafe9-1778921977252-zcz34h.jpeg" -O img_gips_psychiatric_14may.jpeg && \ wget -q "https://d361swluvexzqs.cloudfront.net/chats-attachments/d1d5d04e-75fc-45bb-bf7b-375ac440ddb9-1778921977271-jsk29d.jpeg" -O img_sunflower_hospital_14may.jpeg && \ ls -lh *.jpeg
python3 << 'EOF' from pypdf import PdfWriter, PdfReader from PIL import Image import io, os ATTACHMENT_DIR = "/home/daytona/workspace/attachments/c7f871f6-a1e2-4417-87aa-84d40ab188cd" IMG_DIR = "/home/daytona/workspace/medical-bills" OUT = "/home/daytona/workspace/medical-bills/Medical_Bills_Date_Wise.pdf" def image_to_pdf_bytes(img_path): """Convert image to a PDF page bytes using reportlab.""" from reportlab.lib.pagesizes import A4 from reportlab.pdfgen import canvas from reportlab.lib.utils import ImageReader buf = io.BytesIO() img = Image.open(img_path) iw, ih = img.size # A4 dimensions aw, ah = A4 # Scale to fit A4 with some margin margin = 20 scale = min((aw - 2*margin) / iw, (ah - 2*margin) / ih) nw, nh = iw * scale, ih * scale x = (aw - nw) / 2 y = (ah - nh) / 2 c = canvas.Canvas(buf, pagesize=A4) c.drawImage(ImageReader(img_path), x, y, width=nw, height=nh) c.save() buf.seek(0) return buf # Date-ordered list: (date_label, type, path) # 1. 04-May-2026 - Unipath Lab bill # 2. 09-May-2026 - Unipath Lab bill # 3. 14-May-2026 - GIPS Pharmacy (image) # 4. 14-May-2026 - GIPS Psychiatric Clinic (image) # 5. 14-May-2026 - Sunflower Hospital (image) # 6. 16-May-2026 - Unipath Lab bill ordered_docs = [ ("pdf", os.path.join(ATTACHMENT_DIR, "60502400444.pdf")), # 04-May-2026 ("pdf", os.path.join(ATTACHMENT_DIR, "60502401284.pdf")), # 09-May-2026 ("img", os.path.join(IMG_DIR, "img_gips_pharmacy_14may.jpeg")), # 14-May-2026 ("img", os.path.join(IMG_DIR, "img_gips_psychiatric_14may.jpeg")),# 14-May-2026 ("img", os.path.join(IMG_DIR, "img_sunflower_hospital_14may.jpeg")),# 14-May-2026 ("pdf", os.path.join(ATTACHMENT_DIR, "60502402198.pdf")), # 16-May-2026 ] writer = PdfWriter() for dtype, path in ordered_docs: print(f"Adding: {os.path.basename(path)} ({dtype})") if dtype == "pdf": reader = PdfReader(path) for page in reader.pages: writer.add_page(page) else: pdf_buf = image_to_pdf_bytes(path) reader = PdfReader(pdf_buf) for page in reader.pages: writer.add_page(page) with open(OUT, "wb") as f: writer.write(f) print(f"\nDone! Pages: {len(writer.pages)}") print(f"Saved to: {OUT}") EOF
| Page | Date | Document |
|---|---|---|
| 1 | 04-May-2026 | Unipath Lab – Lithium & Valproic Acid test bill (60502400444) |
| 2 | 09-May-2026 | Unipath Lab – FBS & PPBS test bill (60502401284) |
| 3 | 14-May-2026 | GIPS Pharmacy – Medicine invoice (Arun Agarwal) |
| 4 | 14-May-2026 | GIPS Psychiatric Clinic – OPD receipt (Dr. Himanshu Desai) |
| 5 | 14-May-2026 | Sunflower Multispeciality Hospital – Follow-up receipt (Dr. Parth Gajjar) |
| 6 | 16-May-2026 | Unipath Lab – Creatinine & Urea test bill (60502402198) |
Medical Bills Date Wise
PDF Document · PDF