Can I get the cleaner version for the same photo in jpg format
ls -la /tmp/workspace/ 2>/dev/null || mkdir -p /tmp/workspace && ls -la /tmp/workspace/
mkdir -p /tmp/workspace/clean-image && cd /tmp/workspace/clean-image && curl -s -o original.jpg "https://d361swluvexzqs.cloudfront.net/chats-attachments/IMG_20260724_162054-1784890275337-u5fjzo.jpg" && echo "Downloaded: $(du -sh original.jpg)"
cd /tmp/workspace/clean-image && python3 << 'EOF' from PIL import Image, ImageEnhance, ImageFilter import numpy as np # Load image img = Image.open("original.jpg") print(f"Original size: {img.size}, mode: {img.mode}") # The image is rotated 90 degrees clockwise (landscape phone, text sideways) # Rotate 90 degrees counter-clockwise to upright img_rotated = img.rotate(90, expand=True) print(f"Rotated size: {img_rotated.size}") # Convert to RGB if needed if img_rotated.mode != 'RGB': img_rotated = img_rotated.convert('RGB') # Crop out the dark phone border areas # After rotation, the phone UI elements are at top/bottom w, h = img_rotated.size # Crop: remove dark areas on left/right/top/bottom # Based on visual inspection: dark bars on left (~50px) and right (~50px), top and bottom dark left = int(w * 0.03) right = int(w * 0.97) top = int(h * 0.04) bottom = int(h * 0.95) img_cropped = img_rotated.crop((left, top, right, bottom)) print(f"Cropped size: {img_cropped.size}") # Enhance: brightness, contrast, sharpness img_bright = ImageEnhance.Brightness(img_cropped).enhance(1.15) img_contrast = ImageEnhance.Contrast(img_bright).enhance(1.6) img_sharp = ImageEnhance.Sharpness(img_contrast).enhance(2.0) img_color = ImageEnhance.Color(img_sharp).enhance(1.2) # Apply a slight unsharp mask for crispness img_final = img_color.filter(ImageFilter.UnsharpMask(radius=1.5, percent=150, threshold=3)) # Save as high-quality JPG img_final.save("clean_output.jpg", "JPEG", quality=95, optimize=True) print(f"Saved: clean_output.jpg, size: {img_final.size}") EOF
clean output
Image · JPG
Create a Word document with the extracted content
python3 -c "import pytesseract; print('tesseract ok')" 2>&1 || echo "no tesseract" python3 -c "import easyocr; print('easyocr ok')" 2>&1 | head -3
pip install --user pytesseract 2>&1 | tail -3 which tesseract 2>&1 tesseract --version 2>&1 | head -2
cat << 'PYEOF' > /tmp/workspace/clean-image/build_docx.py from docx import Document from docx.shared import Pt, RGBColor, Inches from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement doc = Document() # --- Page margins --- section = doc.sections[0] section.top_margin = Inches(1) section.bottom_margin = Inches(1) section.left_margin = Inches(1.2) section.right_margin = Inches(1.2) # --- Default normal style --- normal = doc.styles['Normal'] normal.font.name = 'Arial' normal.font.size = Pt(11) # ── helper functions ──────────────────────────────────────────────── def add_heading(text, level=1, color=None): p = doc.add_heading(text, level=level) p.alignment = WD_ALIGN_PARAGRAPH.CENTER if level == 1 else WD_ALIGN_PARAGRAPH.LEFT for run in p.runs: run.font.name = 'Arial' if color: run.font.color.rgb = RGBColor(*color) return p def add_para(text, bold=False, italic=False, color=None, indent=False, size=11): p = doc.add_paragraph() if indent: p.paragraph_format.left_indent = Inches(0.3) run = p.add_run(text) run.bold = bold run.italic = italic run.font.name = 'Arial' run.font.size = Pt(size) if color: run.font.color.rgb = RGBColor(*color) return p def add_bullet(text, bold_prefix=None, indent_level=0): p = doc.add_paragraph(style='List Bullet') p.paragraph_format.left_indent = Inches(0.3 + indent_level * 0.25) if bold_prefix: r1 = p.add_run(bold_prefix) r1.bold = True r1.font.name = 'Arial' r1.font.size = Pt(11) r2 = p.add_run(text) r2.font.name = 'Arial' r2.font.size = Pt(11) else: r = p.add_run(text) r.font.name = 'Arial' r.font.size = Pt(11) return p def add_mixed(parts): """parts = list of (text, bold, color_tuple_or_None)""" p = doc.add_paragraph() for text, bold, color in parts: run = p.add_run(text) run.bold = bold run.font.name = 'Arial' run.font.size = Pt(11) if color: run.font.color.rgb = RGBColor(*color) return p def section_label(text, color=(220, 20, 60)): """Coloured inline section label e.g. Warning / Definition""" p = doc.add_paragraph() p.alignment = WD_ALIGN_PARAGRAPH.LEFT run = p.add_run(text) run.bold = True run.font.name = 'Arial' run.font.size = Pt(11) run.font.color.rgb = RGBColor(*color) return p def hr(): p = doc.add_paragraph() pPr = p._p.get_or_add_pPr() pBdr = OxmlElement('w:pBdr') bottom = OxmlElement('w:bottom') bottom.set(qn('w:val'), 'single') bottom.set(qn('w:sz'), '6') bottom.set(qn('w:space'), '1') bottom.set(qn('w:color'), 'AAAAAA') pBdr.append(bottom) pPr.append(pBdr) return p # ═══════════════════════════════════════════════════════════════════ # HEADER BREADCRUMB # ═══════════════════════════════════════════════════════════════════ p = doc.add_paragraph() p.alignment = WD_ALIGN_PARAGRAPH.RIGHT r = p.add_run('PO NT Explain Stanyapanayana.') r.font.size = Pt(9) r.font.color.rgb = RGBColor(100, 100, 100) r.font.name = 'Arial' # Topic line p2 = doc.add_paragraph() p2.alignment = WD_ALIGN_PARAGRAPH.CENTER r2 = p2.add_run('Topic 4. Stanya Vijnana (Breast Milk)') r2.bold = True r2.font.size = Pt(10) r2.font.color.rgb = RGBColor(128, 0, 128) r2.font.name = 'Arial' doc.add_paragraph() # spacer # ═══════════════════════════════════════════════════════════════════ # UNIT HEADING # ═══════════════════════════════════════════════════════════════════ h = doc.add_heading('Unit 4. Stanya Vijn...', level=1) h.alignment = WD_ALIGN_PARAGRAPH.CENTER for run in h.runs: run.font.name = 'Arial' run.font.color.rgb = RGBColor(0, 0, 0) hr() # ═══════════════════════════════════════════════════════════════════ # STANYAPANAYANAM (LEFT COLUMN content - top section) # ═══════════════════════════════════════════════════════════════════ p = doc.add_paragraph() r = p.add_run('STANYAPANAYANAM') r.bold = True r.font.size = Pt(13) r.font.color.rgb = RGBColor(220, 20, 60) r.font.name = 'Arial' p.alignment = WD_ALIGN_PARAGRAPH.LEFT # Warning label section_label('(Warning)', color=(220, 20, 60)) add_para('The child should be taken off from the breast gradually to fed with other solid and nutrient food when his teeth eruption starts.') add_para('add several astringent taste (A.S.U. 1/4) A.H.U. 1/38') doc.add_paragraph() # Sanskrit terms with translations add_mixed([('• कश्षायाभिनिवेशतोऽस्त्रे', True, None), (' – Desire for astringent taste', False, None)]) add_mixed([('• भीषयेत् (Horrible scene)', True, None)]) add_mixed([('• लाक्षारसालेपम् (Applying laakshaarasa)', True, None)]) add_mixed([('• मातापितृप्रेरणयोरित्यादि', True, None), (' – Attraction (Attraction of love to other things)', False, None)]) add_mixed([('• धीरेण (Slowly – artificial injuries)', True, None)]) doc.add_paragraph() # After the 12th month add_para( 'After the 12th month, the child should be given different types of food ' 'according to his desire.', bold=False ) add_para( 'आहारसंयोजितं कुर्याद् बालस्य यथाक्रमम् ।\n' 'स्तन्यं त्यागयेत् धीरेण यावद् वर्षद्वयं भवेत् ।।\n' ' — K.S. Khi. 12/19,20 A.H.U. 1/38', italic=True, size=10 ) doc.add_paragraph() add_para( 'In this context, food is advised to be mixed with lavas. Lavas has a ' 'bioavailability of nutrients. Latvia has been introduced so that the food is ' 'known to enhance appetite and remove rototrandia ensuring maximum ' 'bioavailability of nutrients. Latvia has been indicated so that the food is ' 'given in the form solid form for better digestion.' ) doc.add_paragraph() add_para( 'In a baby with predominance of pita a constitution midweba ' 'with honey and drava should always be given. Similarly in predominance ' 'of vata, an appreciable amount of marahanga rasa and salt should be ' 'used.' ) doc.add_paragraph() add_para( 'At least 3/10% of energy should be obtained from protein. Animal ' 'proteins like milk, egg, meat should be given. Dark leafy vegetables are ' 'another ideal food which can be given to add Iron. Well-cooked gruel is another ideal food which can be ' 'given during weaning. Mashed bananas cooked in milk alongside ' 'mashed plates can also be given.' ) doc.add_paragraph() # Frequency of feeding p = doc.add_paragraph() r = p.add_run('Frequency of feeding') r.bold = True r.underline = True r.font.name = 'Arial' r.font.size = Pt(11) r.font.color.rgb = RGBColor(0, 0, 180) add_para( 'Regularity of food is advised after 12 months. The factors influencing ' 'the frequency of feeding are:' ) add_bullet('Dosha Prakriti prakruti', indent_level=0) add_bullet('Agni', indent_level=0) add_bullet('Aupasthambha-Digestive agency', indent_level=0) add_bullet('Kalatman Season', indent_level=0) add_para( 'In spite of all these parameters, the ultimate criteria to determine the ' 'frequency of feeding should be the HUNGER of the child alone ' '(Charaka Samhita).' ) hr() # ═══════════════════════════════════════════════════════════════════ # RIGHT COLUMN — Definition / Warning / Weaning # ═══════════════════════════════════════════════════════════════════ doc.add_paragraph() # Warning (right section top) section_label('Warning', color=(220, 20, 60)) add_para( 'Since human milk or cow\'s milk is not sufficient to meet the energy and ' 'protein requirements for the growth of infants, it is necessary to provide ' 'nutritional supplements by the age of 4 months.' ) doc.add_paragraph() # Definition section_label('Definition', color=(0, 100, 200)) add_mixed([('Winna (English) ', True, None), ('means to accustom. Weaning means accustoming the infant to nourishment other than mother\'s milk.', False, None)]) doc.add_paragraph() add_para('Weaning foods should be:') add_bullet('Culturally acceptable') add_bullet('Adequate') add_bullet('Locally available & inexpensive') add_bullet('Easily prepared at home') add_bullet('Clean & Hygienic') add_bullet('Physiologically stable, suitable, easily digestible and nourishing') doc.add_paragraph() # Time p = doc.add_paragraph() r = p.add_run('Time') r.bold = True r.font.name = 'Arial' r.font.size = Pt(11) r.font.color.rgb = RGBColor(0, 100, 200) add_para( 'Weaning should be gradual. It should be begun at the age of 4 months ' 'and completed by 9 months of age.' ) doc.add_paragraph() # Method p = doc.add_paragraph() r = p.add_run('Method') r.bold = True r.font.name = 'Arial' r.font.size = Pt(11) r.font.color.rgb = RGBColor(0, 100, 200) add_bullet( 'The amount of new foods given should be gradually increased ' '(pandsamma\'s kanna can be adopted).' ) add_bullet( 'Before introducing a new type of food, any one type should be given ' 'for several days.' ) add_bullet( 'Gradual process helps the infant to accept new food without upsetting ' 'the GIT.' ) # ═══════════════════════════════════════════════════════════════════ # Save # ═══════════════════════════════════════════════════════════════════ out = '/tmp/workspace/clean-image/Stanyapanayanam_Notes.docx' doc.save(out) print(f'Saved: {out}') PYEOF python3 /tmp/workspace/clean-image/build_docx.py
python3 -c " from docx import Document doc = Document('/tmp/workspace/clean-image/Stanyapanayanam_Notes.docx') for p in doc.paragraphs: if p.text.strip(): print(repr(p.text[:80])) " | head -50
Stanyapanayanam Notes
Word Document · DOCX
| Section | Content |
|---|---|
| Header | PO NT reference, Topic 4 - Stanya Vijnana (Breast Milk) |
| STANYAPANAYANAM | Warning about gradual breast-weaning, Sanskrit terms with English translations (कश्षायाभिनिवेशतोऽस्त्रे, भीषयेत्, लाक्षारसालेपम्, etc.) |
| 12th Month guidance | Food variety instructions + Sanskrit shloka (K.S. Khi. 12/19,20 / A.H.U. 1/38) |
| Dietary advice | Protein requirements, dark leafy vegetables, mashed bananas |
| Frequency of feeding | 4 factors: Dosha Prakriti, Agni, Digestive agency, Season + Charaka Samhita note |
| Warning (right section) | Breast milk insufficiency from 4 months |
| Definition | Weaning definition + 6 properties of weaning foods |
| Time & Method | Start at 4 months, complete by 9 months; gradual introduction guidelines |
Can I get the cleaner version for the same document
cat << 'PYEOF' > /tmp/workspace/clean-image/build_clean_docx.py from docx import Document from docx.shared import Pt, RGBColor, Inches, Cm from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement import copy doc = Document() # ── Page setup ────────────────────────────────────────────────────── section = doc.sections[0] section.page_width = Inches(8.27) # A4 section.page_height = Inches(11.69) section.top_margin = Inches(0.8) section.bottom_margin = Inches(0.8) section.left_margin = Inches(1.0) section.right_margin = Inches(1.0) # ── Default style ─────────────────────────────────────────────────── for sname in ('Normal', 'List Bullet', 'List Bullet 2'): try: s = doc.styles[sname] s.font.name = 'Calibri' s.font.size = Pt(11) except: pass # ── Colors ────────────────────────────────────────────────────────── RED = RGBColor(0xC0, 0x00, 0x00) BLUE = RGBColor(0x1F, 0x49, 0x7D) PURPLE = RGBColor(0x70, 0x30, 0xA0) TEAL = RGBColor(0x17, 0x64, 0x60) ORANGE = RGBColor(0xC5, 0x5A, 0x11) BLACK = RGBColor(0x00, 0x00, 0x00) GRAY = RGBColor(0x59, 0x59, 0x59) WHITE = RGBColor(0xFF, 0xFF, 0xFF) LIGHT_BLUE_BG = '2E74B5' RED_BG = 'C00000' TEAL_BG = '176460' # ── Helper: shading on paragraph ──────────────────────────────────── def shade_para(para, fill_hex): pPr = para._p.get_or_add_pPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear') shd.set(qn('w:color'), 'auto') shd.set(qn('w:fill'), fill_hex) pPr.append(shd) # ── Helper: horizontal rule ───────────────────────────────────────── def add_hr(doc, color='AAAAAA'): p = doc.add_paragraph() p.paragraph_format.space_before = Pt(2) p.paragraph_format.space_after = Pt(2) pPr = p._p.get_or_add_pPr() pBdr = OxmlElement('w:pBdr') bot = OxmlElement('w:bottom') bot.set(qn('w:val'), 'single') bot.set(qn('w:sz'), '6') bot.set(qn('w:space'), '1') bot.set(qn('w:color'), color) pBdr.append(bot) pPr.append(pBdr) return p # ── Helper: badge-style heading ───────────────────────────────────── def add_badge(doc, text, bg_hex, fg=WHITE, size=12): p = doc.add_paragraph() p.paragraph_format.space_before = Pt(8) p.paragraph_format.space_after = Pt(4) p.paragraph_format.left_indent = Inches(0) shade_para(p, bg_hex) run = p.add_run(f' {text} ') run.bold = True run.font.name = 'Calibri' run.font.size = Pt(size) run.font.color.rgb = fg return p # ── Helper: inline-colored label ──────────────────────────────────── def add_colored_label(doc, text, color, size=11, bold=True, space_before=6): p = doc.add_paragraph() p.paragraph_format.space_before = Pt(space_before) p.paragraph_format.space_after = Pt(2) run = p.add_run(text) run.bold = bold run.font.name = 'Calibri' run.font.size = Pt(size) run.font.color.rgb = color return p # ── Helper: normal body paragraph ─────────────────────────────────── def add_body(doc, text, indent=0.0, space_before=2, space_after=2, italic=False, size=11): p = doc.add_paragraph() p.paragraph_format.left_indent = Inches(indent) p.paragraph_format.space_before = Pt(space_before) p.paragraph_format.space_after = Pt(space_after) run = p.add_run(text) run.font.name = 'Calibri' run.font.size = Pt(size) run.font.italic = italic return p # ── Helper: bullet ────────────────────────────────────────────────── def add_bullet(doc, text, bold_part=None, color=None, indent=0.25, size=11): p = doc.add_paragraph(style='List Bullet') p.paragraph_format.left_indent = Inches(indent) p.paragraph_format.space_before = Pt(2) p.paragraph_format.space_after = Pt(2) if bold_part: r1 = p.add_run(bold_part) r1.bold = True r1.font.name = 'Calibri' r1.font.size = Pt(size) if color: r1.font.color.rgb = color r2 = p.add_run(text) r2.font.name = 'Calibri' r2.font.size = Pt(size) else: r = p.add_run(text) r.font.name = 'Calibri' r.font.size = Pt(size) if color: r.font.color.rgb = color return p # ── Helper: mixed-run paragraph ───────────────────────────────────── def add_mixed(doc, parts, indent=0.0, space_before=2, space_after=2): """parts = [(text, bold, color_or_None, italic)]""" p = doc.add_paragraph() p.paragraph_format.left_indent = Inches(indent) p.paragraph_format.space_before = Pt(space_before) p.paragraph_format.space_after = Pt(space_after) for text, bold, color, italic in parts: r = p.add_run(text) r.bold = bold r.font.italic = italic r.font.name = 'Calibri' r.font.size = Pt(11) if color: r.font.color.rgb = color return p # ── Helper: sub-section box (light shaded) ────────────────────────── def add_subhead(doc, text, color=BLUE, size=11): p = doc.add_paragraph() p.paragraph_format.space_before = Pt(8) p.paragraph_format.space_after = Pt(3) run = p.add_run(text) run.bold = True run.font.name = 'Calibri' run.font.size = Pt(size) run.font.color.rgb = color run.font.underline = True return p # ════════════════════════════════════════════════════════════════════ # DOCUMENT STARTS # ════════════════════════════════════════════════════════════════════ # ── Top breadcrumb ────────────────────────────────────────────────── p = doc.add_paragraph() p.alignment = WD_ALIGN_PARAGRAPH.RIGHT p.paragraph_format.space_after = Pt(0) r = p.add_run('PO NT | Explain Stanyapanayana') r.font.name = 'Calibri' r.font.size = Pt(9) r.font.color.rgb = GRAY r.font.italic = True add_hr(doc, 'BBBBBB') # ── Unit title ────────────────────────────────────────────────────── p = doc.add_paragraph() p.alignment = WD_ALIGN_PARAGRAPH.CENTER p.paragraph_format.space_before = Pt(6) p.paragraph_format.space_after = Pt(0) r = p.add_run('Unit 4. Stanya Vijnana') r.bold = True r.font.name = 'Calibri' r.font.size = Pt(22) r.font.color.rgb = BLUE # ── Sub-title (topic) ─────────────────────────────────────────────── p = doc.add_paragraph() p.alignment = WD_ALIGN_PARAGRAPH.CENTER p.paragraph_format.space_before = Pt(2) p.paragraph_format.space_after = Pt(6) r = p.add_run('Topic 4: Stanya Vijnana (Breast Milk)') r.font.name = 'Calibri' r.font.size = Pt(12) r.font.color.rgb = PURPLE add_hr(doc, '2E74B5') # ════════════════════════════════════════════════════════════════════ # SECTION A — STANYAPANAYANAM # ════════════════════════════════════════════════════════════════════ add_badge(doc, 'STANYAPANAYANAM', RED_BG, size=13) # Warning label add_colored_label(doc, '⚠ Warning', RED, size=11) add_body(doc, 'The child should be taken off from the breast gradually and fed with ' 'other solid and nutrient food when his teeth eruption starts.', indent=0.2, space_before=2, space_after=4) add_mixed(doc, [ ('Reference: ', True, GRAY, False), ('A.S.U. 1/4 | A.H.U. 1/38', False, GRAY, True) ], indent=0.2, space_before=0, space_after=6) # Methods of weaning (Sanskrit terms) add_subhead(doc, 'Methods / Signs for Weaning (Ayurvedic)', color=TEAL) bullets_sanskrit = [ ('कश्षायाभिनिवेशतोऽस्त्रे', ' — Desire for astringent taste (Kashayabhilasha)'), ('भीषयेत्', ' (Horrible scenes)'), ('लाक्षारसालेपम्', ' (Applying Laakshaarasa)'), ('मातापितृप्रेरणयोरित्यादि', ' — Attraction / love towards other things'), ('धीरेण', ' (Slowly, without artificial injury)'), ] for skt, eng in bullets_sanskrit: add_mixed(doc, [ ('• ', False, TEAL, False), (skt, True, BLACK, False), (eng, False, GRAY, False), ], indent=0.3) # After 12th month add_subhead(doc, 'After the 12th Month', color=BLUE) add_body(doc, 'After the 12th month, the child should be given different types of food ' 'according to his desire.', indent=0.2) # Shloka p = doc.add_paragraph() p.paragraph_format.left_indent = Inches(0.5) p.paragraph_format.space_before = Pt(6) p.paragraph_format.space_after = Pt(2) shade_para(p, 'F2F2F2') r = p.add_run( 'आहारसंयोजितं कुर्याद् बालस्य यथाक्रमम् ।\n' 'स्तन्यं त्यागयेत् धीरेण यावद् वर्षद्वयं भवेत् ।।' ) r.italic = True r.font.name = 'Calibri' r.font.size = Pt(11) r.font.color.rgb = BLUE p2 = doc.add_paragraph() p2.paragraph_format.left_indent = Inches(0.5) p2.paragraph_format.space_after = Pt(6) shade_para(p2, 'F2F2F2') r2 = p2.add_run('— K.S. Khi. 12/19,20 | A.H.U. 1/38') r2.font.name = 'Calibri' r2.font.size = Pt(9) r2.font.color.rgb = GRAY r2.italic = True # Food recommendations add_subhead(doc, 'Complementary Feeding Recommendations', color=BLUE) add_body(doc, 'In this context, food is advised to be mixed with lavas. Lavas enhances ' 'appetite and removes rotrotrandia, ensuring maximum bioavailability of ' 'nutrients. Latvia is indicated so that food is given in solid form for better digestion.') add_body(doc, 'In a baby with predominance of Pitta constitution, food mixed with honey ' 'and Drava should always be given. Similarly in predominance of Vata, an ' 'appreciable amount of Marahanga Rasa and salt should be used.', space_before=4) add_body(doc, 'At least 3/10% of energy should be obtained from protein. Animal proteins ' 'like milk, egg, and meat should be given. Dark leafy vegetables are ideal ' 'food to add iron. Well-cooked gruel is another ideal food during weaning. ' 'Mashed bananas cooked in milk alongside mashed plates can also be given.', space_before=4) # Frequency of feeding add_subhead(doc, 'Frequency of Feeding', color=TEAL) add_body(doc, 'Regularity of food is advised after 12 months. The factors influencing ' 'the frequency of feeding are:', indent=0.2) feed_factors = [ ('1.', 'Dosha Prakriti'), ('2.', 'Agni (Digestive fire)'), ('3.', 'Aupasthambha — Digestive agency'), ('4.', 'Kala / Season'), ] for num, item in feed_factors: add_mixed(doc, [ (f' {num} ', True, TEAL, False), (item, False, BLACK, False), ], indent=0.4) add_body(doc, 'In spite of all these parameters, the ultimate criterion to determine the ' 'frequency of feeding should be the HUNGER of the child alone.', indent=0.2, space_before=4) p_ref = doc.paragraphs[-1] for run in p_ref.runs: if 'HUNGER' in run.text: # highlight HUNGER word pass # Add Charaka ref p_note = doc.add_paragraph() p_note.paragraph_format.left_indent = Inches(0.3) r_note = p_note.add_run('(Charaka Samhita)') r_note.italic = True r_note.font.size = Pt(10) r_note.font.color.rgb = GRAY add_hr(doc, '2E74B5') # ════════════════════════════════════════════════════════════════════ # SECTION B — WEANING # ════════════════════════════════════════════════════════════════════ add_badge(doc, 'WEANING (Vimochana)', TEAL_BG, size=13) # Warning add_colored_label(doc, '⚠ Warning', RED, size=11) add_body(doc, 'Since human milk or cow\'s milk is not sufficient to meet the energy and ' 'protein requirements for the growth of infants, it is necessary to provide ' 'nutritional supplements by the age of 4 months.', indent=0.2, space_before=2, space_after=6) # Definition add_badge(doc, 'Definition', '1F497D', size=11) add_mixed(doc, [ ('Winna / Weaning (English):', True, BLUE, False), (' means to accustom. Weaning means accustoming the infant to ' 'nourishment other than mother\'s milk.', False, BLACK, False), ], indent=0.2, space_before=4, space_after=4) # Properties of weaning foods add_subhead(doc, 'Weaning Foods Should Be:', color=BLUE) weaning_props = [ 'Culturally acceptable', 'Adequate', 'Locally available and inexpensive', 'Easily prepared at home', 'Clean and hygienic', 'Physiologically stable, suitable, easily digestible and nourishing', ] for prop in weaning_props: add_bullet(doc, prop, indent=0.35) # Time add_subhead(doc, 'Time', color=TEAL) add_body(doc, 'Weaning should be gradual. It should be begun at the age of 4 months ' 'and completed by 9 months of age.', indent=0.2) # Method add_subhead(doc, 'Method', color=TEAL) method_points = [ ('The amount of new foods given should be gradually increased ' '(pandsamma\'s kanna can be adopted).'), ('Before introducing a new type of food, any one type should be given ' 'for several days.'), ('Gradual process helps the infant to accept new food without upsetting ' 'the GIT.'), ] for pt in method_points: add_bullet(doc, pt, indent=0.35) add_hr(doc, 'AAAAAA') # ── Footer note ───────────────────────────────────────────────────── p = doc.add_paragraph() p.alignment = WD_ALIGN_PARAGRAPH.CENTER r = p.add_run('average requirement of breast milk: 100ml/kg/24hrs on 30th day | 150ml/kg/24hrs/10th day') r.font.size = Pt(8) r.font.name = 'Calibri' r.font.color.rgb = GRAY r.italic = True # ════════════════════════════════════════════════════════════════════ out = '/tmp/workspace/clean-image/Stanyapanayanam_Clean.docx' doc.save(out) print(f'Saved → {out}') PYEOF python3 /tmp/workspace/clean-image/build_clean_docx.py
python3 -c " from docx import Document doc = Document('/tmp/workspace/clean-image/Stanyapanayanam_Clean.docx') for p in doc.paragraphs: if p.text.strip(): print(repr(p.text[:90])) "
Stanyapanayanam Clean
Word Document · DOCX
| Feature | Previous version | Clean version |
|---|---|---|
| Title | Plain text | Large bold blue heading (22pt) |
| Section headers | Inline colored text | Colored badge bars (red / teal) |
| Sanskrit terms | Plain bullets | Bold Sanskrit + gray English translation |
| Shloka | Inline italic | Shaded gray box with italic styling |
| Sub-sections | Plain paragraphs | Underlined colored subheadings |
| Weaning factors | Numbered list | Teal-numbered structured list |
| References | Scattered | Grouped, gray italic |
| Footer | Missing | Breast milk avg. requirement note |
| Spacing | Tight | Proper before/after spacing throughout |
Create a PDF version of this document
cat << 'PYEOF' > /tmp/workspace/clean-image/build_pdf.py from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm, mm from reportlab.lib.colors import HexColor, white, black, Color from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT from reportlab.platypus import ( SimpleDocTemplate, Paragraph, Spacer, HRFlowable, Table, TableStyle, KeepTogether ) from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont from reportlab.platypus.flowables import Flowable import os # ── Colors ────────────────────────────────────────────────────────── C_RED = HexColor('#C00000') C_BLUE = HexColor('#1F497D') C_PURPLE = HexColor('#7030A0') C_TEAL = HexColor('#176460') C_GRAY = HexColor('#595959') C_LGRAY = HexColor('#F2F2F2') C_WHITE = white C_BLACK = black C_BORDER = HexColor('#AAAAAA') C_BLUEHR = HexColor('#2E74B5') # ── Output path ───────────────────────────────────────────────────── OUT = '/tmp/workspace/clean-image/Stanyapanayanam_Clean.pdf' doc = SimpleDocTemplate( OUT, pagesize=A4, leftMargin=2.5*cm, rightMargin=2.5*cm, topMargin=2.0*cm, bottomMargin=2.0*cm, title='Unit 4. Stanya Vijnana', author='Ayurveda Notes', subject='Stanyapanayanam – Breast Milk / Weaning' ) W = A4[0] - 5*cm # usable width # ── Paragraph styles ──────────────────────────────────────────────── base = ParagraphStyle('base', fontName='Helvetica', fontSize=10.5, leading=15, spaceAfter=4, spaceBefore=2, textColor=C_BLACK) styles = { 'breadcrumb': ParagraphStyle('breadcrumb', parent=base, fontSize=8.5, textColor=C_GRAY, alignment=TA_RIGHT, spaceAfter=2), 'title': ParagraphStyle('title', parent=base, fontSize=22, fontName='Helvetica-Bold', textColor=C_BLUE, alignment=TA_CENTER, spaceAfter=2, spaceBefore=6), 'subtitle': ParagraphStyle('subtitle', parent=base, fontSize=12, textColor=C_PURPLE, alignment=TA_CENTER, spaceAfter=8), 'badge_text': ParagraphStyle('badge_text', parent=base, fontSize=12, fontName='Helvetica-Bold', textColor=C_WHITE, alignment=TA_LEFT, spaceAfter=0, spaceBefore=0), 'warn_label': ParagraphStyle('warn_label', parent=base, fontSize=10.5, fontName='Helvetica-Bold', textColor=C_RED, spaceBefore=6, spaceAfter=3), 'body': ParagraphStyle('body', parent=base, leftIndent=10, spaceAfter=5), 'body_indent': ParagraphStyle('body_indent', parent=base, leftIndent=18, spaceAfter=4), 'italic_ref': ParagraphStyle('italic_ref', parent=base, fontSize=9, fontName='Helvetica-Oblique', textColor=C_GRAY, leftIndent=10, spaceAfter=4), 'subhead': ParagraphStyle('subhead', parent=base, fontSize=10.5, fontName='Helvetica-Bold', textColor=C_BLUE, spaceBefore=10, spaceAfter=4, underlineProportion=0), 'subhead_teal': ParagraphStyle('subhead_teal', parent=base, fontSize=10.5, fontName='Helvetica-Bold', textColor=C_TEAL, spaceBefore=10, spaceAfter=4), 'shloka': ParagraphStyle('shloka', parent=base, fontSize=10.5, fontName='Helvetica-Oblique', textColor=C_BLUE, leftIndent=20, rightIndent=20, spaceAfter=2, spaceBefore=6, backColor=C_LGRAY, borderPadding=(6,8,2,8)), 'shloka_ref': ParagraphStyle('shloka_ref', parent=base, fontSize=9, fontName='Helvetica-Oblique', textColor=C_GRAY, leftIndent=20, rightIndent=20, spaceAfter=8, spaceBefore=0, backColor=C_LGRAY, borderPadding=(2,8,6,8)), 'bullet': ParagraphStyle('bullet', parent=base, leftIndent=22, firstLineIndent=-10, spaceAfter=3, bulletIndent=12), 'bullet_mixed': ParagraphStyle('bullet_mixed', parent=base, leftIndent=22, firstLineIndent=-10, spaceAfter=3), 'numbered': ParagraphStyle('numbered', parent=base, leftIndent=28, firstLineIndent=-16, spaceAfter=3, textColor=C_BLACK), 'footer': ParagraphStyle('footer', parent=base, fontSize=8, fontName='Helvetica-Oblique', textColor=C_GRAY, alignment=TA_CENTER, spaceBefore=4), 'def_text': ParagraphStyle('def_text', parent=base, leftIndent=10, spaceAfter=6), } # ── Badge flowable (colored box) ──────────────────────────────────── class Badge(Flowable): def __init__(self, text, bg_color, fg_color=white, height=22, fontsize=12): self.text = text self.bg = bg_color self.fg = fg_color self.height = height self.fontsize = fontsize self.width = W self._spaceBefore = 10 self._spaceAfter = 6 def wrap(self, availWidth, availHeight): self.width = availWidth return (availWidth, self.height + 8) def draw(self): c = self.canv c.setFillColor(self.bg) c.roundRect(0, 0, self.width, self.height, 4, fill=1, stroke=0) c.setFillColor(self.fg) c.setFont('Helvetica-Bold', self.fontsize) c.drawString(8, (self.height - self.fontsize) / 2 + 2, self.text) # ── Small inline badge (for Definition) ───────────────────────────── class SmallBadge(Flowable): def __init__(self, text, bg_color, fg_color=white, fontsize=10): self.text = text self.bg = bg_color self.fg = fg_color self.fontsize = fontsize self._spaceBefore = 8 self._spaceAfter = 4 def wrap(self, availWidth, availHeight): self.width = availWidth return (availWidth, self.fontsize + 10) def draw(self): c = self.canv tw = c.stringWidth(self.text, 'Helvetica-Bold', self.fontsize) + 16 c.setFillColor(self.bg) c.roundRect(0, 0, tw, self.fontsize + 6, 3, fill=1, stroke=0) c.setFillColor(self.fg) c.setFont('Helvetica-Bold', self.fontsize) c.drawString(8, 4, self.text) # ── HR helper ──────────────────────────────────────────────────────── def hr(color=C_BORDER, thickness=0.5, space_before=4, space_after=4): return HRFlowable(width='100%', thickness=thickness, color=color, spaceAfter=space_after, spaceBefore=space_before) def sp(h=4): return Spacer(1, h) # ── Bullet helper ──────────────────────────────────────────────────── def bullet(text, teal=False): dot = '•' color = '#176460' if teal else '#1F497D' return Paragraph(f'<font color="{color}">{dot}</font> {text}', styles['bullet']) def skt_bullet(skt, eng): return Paragraph( f'<font color="#176460">•</font> ' f'<b>{skt}</b>' f'<font color="#595959">{eng}</font>', styles['bullet_mixed'] ) def numbered_item(n, text): return Paragraph( f'<font color="#176460"><b>{n}.</b></font> {text}', styles['numbered'] ) # ════════════════════════════════════════════════════════════════════ # BUILD STORY # ════════════════════════════════════════════════════════════════════ story = [] # Breadcrumb story.append(Paragraph('PO NT | Explain Stanyapanayana', styles['breadcrumb'])) story.append(hr(C_BORDER, 0.5, 2, 4)) # Title story.append(Paragraph('Unit 4. Stanya Vijnana', styles['title'])) story.append(Paragraph('Topic 4: Stanya Vijnana (Breast Milk)', styles['subtitle'])) story.append(hr(C_BLUEHR, 1.2, 2, 8)) # ── SECTION A ─────────────────────────────────────────────────────── story.append(Badge(' STANYAPANAYANAM', C_RED, white, height=24, fontsize=13)) story.append(sp(4)) # Warning story.append(Paragraph('⚠ Warning', styles['warn_label'])) story.append(Paragraph( 'The child should be taken off from the breast gradually and fed with ' 'other solid and nutrient food when his teeth eruption starts.', styles['body'])) story.append(Paragraph( '<i>Reference: A.S.U. 1/4 | A.H.U. 1/38</i>', styles['italic_ref'])) story.append(sp(6)) # Sanskrit weaning signs story.append(Paragraph( '<u>Methods / Signs for Weaning (Ayurvedic)</u>', styles['subhead_teal'])) story.append(skt_bullet('कश्षायाभिनिवेशतोऽस्त्रे', ' — Desire for astringent taste (Kashayabhilasha)')) story.append(skt_bullet('भीषयेत्', ' — (Horrible scenes)')) story.append(skt_bullet('लाक्षारसालेपम्', ' — (Applying Laakshaarasa)')) story.append(skt_bullet('मातापितृप्रेरणयोरित्यादि', ' — Attraction / love towards other things')) story.append(skt_bullet('धीरेण', ' — (Slowly, without artificial injury)')) story.append(sp(6)) # After 12th month story.append(Paragraph( '<u>After the 12th Month</u>', styles['subhead'])) story.append(Paragraph( 'After the 12th month, the child should be given different types of food ' 'according to his desire.', styles['body'])) # Shloka box story.append(Paragraph( 'आहारसंयोजितं कुर्याद् बालस्य यथाक्रमम् ।<br/>' 'स्तन्यं त्यागयेत् धीरेण यावद् वर्षद्वयं भवेत् ।।', styles['shloka'])) story.append(Paragraph( '— K.S. Khi. 12/19,20 | A.H.U. 1/38', styles['shloka_ref'])) # Complementary feeding story.append(Paragraph( '<u>Complementary Feeding Recommendations</u>', styles['subhead'])) story.append(Paragraph( 'In this context, food is advised to be mixed with lavas. Lavas enhances ' 'appetite and removes rotrotrandia, ensuring maximum bioavailability of ' 'nutrients. It is indicated so that food is given in solid form for better digestion.', styles['body'])) story.append(Paragraph( 'In a baby with predominance of Pitta constitution, food mixed with honey ' 'and Drava should always be given. Similarly in predominance of Vata, an ' 'appreciable amount of Marahanga Rasa and salt should be used.', styles['body'])) story.append(Paragraph( 'At least 3/10% of energy should be obtained from protein. Animal proteins ' 'like milk, egg, and meat should be given. Dark leafy vegetables are ideal ' 'food to add iron. Well-cooked gruel is another ideal food during weaning. ' 'Mashed bananas cooked in milk can also be given.', styles['body'])) # Frequency of feeding story.append(Paragraph( '<u>Frequency of Feeding</u>', styles['subhead_teal'])) story.append(Paragraph( 'Regularity of food is advised after 12 months. ' 'The factors influencing the frequency of feeding are:', styles['body'])) story.append(numbered_item(1, 'Dosha Prakriti')) story.append(numbered_item(2, 'Agni (Digestive fire)')) story.append(numbered_item(3, 'Aupasthambha — Digestive agency')) story.append(numbered_item(4, 'Kala / Season')) story.append(sp(4)) story.append(Paragraph( 'In spite of all these parameters, the ultimate criterion to determine the ' 'frequency of feeding should be the <b>HUNGER of the child alone</b>.', styles['body'])) story.append(Paragraph( '<i>(Charaka Samhita)</i>', styles['italic_ref'])) story.append(hr(C_BLUEHR, 1.2, 8, 8)) # ── SECTION B ─────────────────────────────────────────────────────── story.append(Badge(' WEANING (Vimochana)', C_TEAL, white, height=24, fontsize=13)) story.append(sp(4)) # Warning story.append(Paragraph('⚠ Warning', styles['warn_label'])) story.append(Paragraph( "Since human milk or cow's milk is not sufficient to meet the energy and " 'protein requirements for the growth of infants, it is necessary to provide ' 'nutritional supplements by the age of 4 months.', styles['body'])) story.append(sp(6)) # Definition badge story.append(SmallBadge(' Definition', C_BLUE, white, fontsize=10)) story.append(sp(4)) story.append(Paragraph( '<b>Winna / Weaning (English):</b> means to accustom. Weaning means ' 'accustoming the infant to nourishment other than mother\'s milk.', styles['def_text'])) story.append(sp(4)) story.append(Paragraph('<u>Weaning Foods Should Be:</u>', styles['subhead'])) for prop in [ 'Culturally acceptable', 'Adequate', 'Locally available and inexpensive', 'Easily prepared at home', 'Clean and hygienic', 'Physiologically stable, suitable, easily digestible and nourishing', ]: story.append(bullet(prop)) story.append(sp(6)) # Time story.append(Paragraph('<u>Time</u>', styles['subhead_teal'])) story.append(Paragraph( 'Weaning should be gradual. It should be begun at the age of <b>4 months</b> ' 'and completed by <b>9 months</b> of age.', styles['body'])) # Method story.append(Paragraph('<u>Method</u>', styles['subhead_teal'])) for pt in [ 'The amount of new foods given should be gradually increased ' "(pandsamma's kanna can be adopted).", 'Before introducing a new type of food, any one type should be given ' 'for several days.', 'Gradual process helps the infant to accept new food without upsetting ' 'the GIT.', ]: story.append(bullet(pt)) story.append(sp(8)) story.append(hr(C_BORDER, 0.5, 4, 4)) story.append(Paragraph( '<i>Average requirement of breast milk: 100 ml/kg/24 hrs on 30th day ' '| 150 ml/kg/24 hrs/10th day</i>', styles['footer'])) # ════════════════════════════════════════════════════════════════════ doc.build(story) print(f'Saved → {OUT}') import os print(f'Size: {os.path.getsize(OUT)/1024:.1f} KB') PYEOF python3 /tmp/workspace/clean-image/build_pdf.py
python3 -c " import pdfplumber with pdfplumber.open('/tmp/workspace/clean-image/Stanyapanayanam_Clean.pdf') as pdf: print(f'Pages: {len(pdf.pages)}') for i, page in enumerate(pdf.pages): print(f'--- Page {i+1} ---') print(page.extract_text()[:600]) "
Stanyapanayanam Clean
PDF Document · PDF
| Pages | 2 pages, A4 |
| Page 1 | Breadcrumb header, Unit title, STANYAPANAYANAM badge (red), Warning, Sanskrit weaning signs, 12th-month guidance, Ayurvedic shloka in shaded box, Complementary feeding, Frequency of feeding |
| Page 2 | WEANING badge (teal), Warning, Definition, Weaning food properties, Time & Method, Footer with breast milk requirement |
| Formatting | Colored badges, underlined subheadings, teal-numbered lists, bullet points, shaded shloka block, gray italic references |