~/medicine-pdf/generate_pdf.py
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer, HRFlowable
from reportlab.lib.enums import TA_CENTER, TA_LEFT
output_path = "/tmp/workspace/medicine-pdf/Medicines_by_Disease.pdf"
doc = SimpleDocTemplate(
output_path,
pagesize=A4,
rightMargin=1.5*cm,
leftMargin=1.5*cm,
topMargin=2*cm,
bottomMargin=2*cm
)
styles = getSampleStyleSheet()
title_style = ParagraphStyle(
'Title', parent=styles['Title'],
fontSize=18, textColor=colors.HexColor('#1a3c6b'),
spaceAfter=10, alignment=TA_CENTER
)
subtitle_style = ParagraphStyle(
'Subtitle', parent=styles['Normal'],
fontSize=10, textColor=colors.HexColor('#555555'),
spaceAfter=20, alignment=TA_CENTER
)
section_style = ParagraphStyle(
'Section', parent=styles['Normal'],
fontSize=12, textColor=colors.white,
fontName='Helvetica-Bold', spaceAfter=4, spaceBefore=12,
alignment=TA_LEFT, leftIndent=4
)
normal_style = ParagraphStyle(
'Normal2', parent=styles['Normal'],
fontSize=8.5, spaceAfter=2
)
# Color palette for section headers
section_colors = [
'#1a3c6b', '#2e7d32', '#b71c1c', '#6a1b9a', '#e65100',
'#00695c', '#283593', '#4e342e', '#37474f', '#558b2f',
'#ad1457', '#1565c0', '#bf360c', '#1b5e20', '#4a148c'
]
categories = [
{
"title": "🫀 Cardiovascular / Hypertension / Heart Failure",
"data": [
["Brand Name", "Composition"],
["Amlong 2.5 / Acord 5 / Amlodac 5", "Amlodipine"],
["Acord M 50", "Metoprolol succinate + Metoprolol tartrate + Amlodipine besylate"],
["Aldactone", "Spironolactone"],
["Cardace 5 / 1.25 / 2.5", "Ramipril"],
["Cardivas 3.125 / 6.25", "Carvedilol"],
["Cilacar 10mg", "Cilnidipine 10mg"],
["CTD 6.5", "Chlorthalidone 6.25mg"],
["Concor 1.25 / 2.5", "Bisoprolol fumarate"],
["Dytor Plus 10 / 5", "Torsemide + Spironolactone"],
["Dytor 10 / 5", "Torsemide"],
["Ecosprin AV75", "Atorvastatin 10 + Aspirin 75"],
["Envas 5 / 2.5", "Enalapril"],
["Lasix 40", "Frusemide 10mg"],
["Lasilactone 50", "Frusemide 20 + Spironolactone 50"],
["Prolomet XL50", "Metoprolol succinate + Metoprolol tartrate"],
["Telex AM", "Telmisartan 40 + Amlodipine 5"],
["Telex 20/40 / Telmiwal H", "Telmisartan"],
]
},
{
"title": "🩸 Lipid-Lowering / Statins",
"data": [
["Brand Name", "Composition"],
["Atolife 40 / 20", "Atorvastatin"],
["Atolife 20 Gold", "Atorvastatin + Clopidogrel + Aspirin"],
["Ecosprin AV75", "Atorvastatin + Aspirin"],
]
},
{
"title": "🧠 Anxiety / Sedation / Neurological",
"data": [
["Brand Name", "Composition"],
["Anxit 0.25 / 0.50", "Alprazolam"],
["Atarax 10", "Hydroxyzine HCl 10mg"],
["Bacfen 5 / 10", "Baclofen"],
["Levipil 500", "Levetiracetam 500mg"],
["Nexito Plus", "Escitalopram 5mg"],
["Pregabalift NT", "Pregabalin 75 + Nortriptyline 10mg"],
["Strocit Plus", "Piracetam + Citicoline"],
["Sibelium 10", "Flunarizine dihydrochloride 10mg"],
]
},
{
"title": "🤧 Allergy / Antihistamine",
"data": [
["Brand Name", "Composition"],
["Allegra", "Fexofenadine HCl 120mg"],
["Allercet DC", "Ebastine 10 + Phenylephrine HCl 10mg"],
["Allercet Ped", "Cetirizine HCl 5mg dispersible"],
["Alerid / Cetzine 10", "Cetirizine HCl 10mg"],
["Elina 10", "Mizolastine Modified Release 10mg"],
["Montair LC / LC Kid", "Montelukast + Levocetirizine"],
["Lasma 4mg / 5mg", "Montelukast Na mouth dissolving"],
["Xyzal M", "Levocetirizine + Montelukast"],
]
},
{
"title": "🫁 Respiratory / Asthma / COPD",
"data": [
["Brand Name", "Composition"],
["Aceday 100", "Acebrophylline 100mg"],
["Asthanik 100", "Bronchodilator"],
["Aeflo 1", "Bronchodilator"],
["Deriphyllin 300 / 150", "Etofylline 115 + Theophylline anhydrous 35mg"],
["Doxolin", "Doxofylline 400mg"],
["Hypercet FX", "Acebrophylline 100mg + Acetylcysteine 600mg"],
["Levolin 1mg syr", "Levosalbutamol syrup"],
["Nefrosave", "Taurine + Acetylcysteine"],
]
},
{
"title": "🦠 Antibiotics / Antimicrobials",
"data": [
["Brand Name", "Composition"],
["Althrocin 250 / 500", "Erythromycin estolate"],
["Azobat 250 / Azinik 500", "Azithromycin"],
["Ceftilox 200 / 100", "Cefixime dispersible"],
["Dixomax CV 375 / 625", "Amoxicillin trihydrate 250mg + K Clavulanic acid 125mg"],
["Evermox C", "Amoxicillin 250 + Cloxacillin 250 + Lactic acid bacillus"],
["Levoflox 750 / 500", "Levofloxacin hemihydrate"],
["Lizoforce 600", "Linezolid 600mg"],
["Mahacef CV 200", "Cefixime 200 + Clavulanic acid 125"],
["Norflox 400", "Norfloxacin + Lactic acid bacillus"],
["OFY 200", "Ofloxacin 200mg"],
["OFY OZ", "Ofloxacin 200 + Ornidazole 500mg"],
["Taxim O / cefixime 50/100 sus", "Cefixime"],
["Flagyl 200", "Metronidazole"],
["Zancocin 200/OZ", "Ofloxacin"],
]
},
{
"title": "🦠 Antiviral",
"data": [
["Brand Name", "Composition"],
["Antiflu 75", "Oseltamivir phosphate 75mg"],
["Zovirax 400 / 800", "Aciclovir 400mg / 800mg"],
]
},
{
"title": "🤢 Gastro / GI / Nausea / Vomiting / Acidity",
"data": [
["Brand Name", "Composition"],
["Arbez D", "Rabeprazole Na 20mg + Domperidone 10mg"],
["Cyclopam", "Dicyclomine HCl 20mg + Paracetamol 500mg"],
["Domestal 10 / Domstal Baby", "Domperidone"],
["Dulcoflex", "Bisacodyl 5mg"],
["Eldopper 2", "Loperamide HCl 2mg"],
["Emeset 4", "Ondansetron 4mg"],
["Flavospas / Urispas", "Flavoxate 200mg"],
["G-PantoDSR", "Pantoprazole 40 + Domperidone 30"],
["Junior Lanzol 15 / 30", "Lansoprazole orally disintegrating"],
["Meftal SPAS", "Mefenamic acid 250 + Dicyclomine HCl 10"],
["Nexpro 40", "Esomeprazole Mg"],
["Nodosis", "Sodium Bicarbonate"],
["PanD / Pantalife 40", "Pantoprazole 40 + Domperidone / Pantoprazole 40"],
["Razep / Rabinta", "Rabeprazole 20mg"],
["Sompraz D", "Esomeprazole + Domperidone"],
]
},
{
"title": "🩹 Pain / Anti-inflammatory / Muscle Relaxant",
"data": [
["Brand Name", "Composition"],
["Ace Wok Plus / Zerodol SP", "Aceclofenac 100mg + Paracetamol 325mg + Serratiopeptidase 15mg"],
["Acton OR", "Paracetamol SR (300mg immediate + 700mg sustained)"],
["Brufen 200 / 400", "Ibuprofen 200mg / 400mg"],
["Chymoralforte", "Trypsin + Chymotrypsin"],
["Combiflam", "Ibuprofen 400 + Paracetamol 325mg"],
["Imol Plus", "Ibuprofen 400 + Paracetamol 325 + Caffeine 25mg"],
["Ketorol", "Ketorolac tromethamine 10mg"],
["Lyser Forte", "Serratiopeptidase 10mg"],
["P 250", "Dispersible Paracetamol"],
["Traphic / Traphic MF", "Tranexamic acid / + Mefenamic acid"],
["Ultract", "Paracetamol 325 + Tramadol HCl 37.5mg"],
["Zerodol P", "Aceclofenac 100 + Paracetamol 325mg"],
["Zerodol TH4", "Aceclofenac 100 + Thiocolchicoside 4mg"],
["Zerodol Spas", "Aceclofenac 100 + Drotaverine HCl 80mg"],
]
},
{
"title": "🩸 Diabetes / Blood Sugar",
"data": [
["Brand Name", "Composition"],
["Dibizide M", "Glipizide 5mg + Metformin HCl 500mg"],
["Glynase MF", "Glipizide 5 + Metformin HCl 500mg"],
["Glitastar 15", "Pioglitazone 15mg"],
["Glycinorm M40", "Gliclazide 40 + Metformin HCl 500mg"],
["Glycomet GP 0.5 / 1 / 2", "Metformin HCl prol rel 500mg + Glimepiride"],
["Glycomet SR500 / 500 / 250", "Metformin HCl"],
["Gludart M1 / M2", "Metformin combinations"],
["Istamet 500", "Sitagliptin 50 + Metformin HCl 500mg"],
["Istamet DXR", "Dapagliflozin + Sitagliptin + Metformin ext rel"],
["Revilda D", "Dapagliflozin 10 + Vidagliptin 100SR"],
["Sitanow M 500", "Metformin + Sitagliptin"],
["Sugamide M1 / M2", "Metformin HCl 500 + Glimepiride 1/2mg"],
["Tenifix 20", "Teneligliptin 20mg"],
["Tenlifast M 500", "Teneligliptin + Metformin ER 500mg"],
["Trajenta 5mg", "Linagliptin"],
["V.VOG", "Voglibose mouth dissolving"],
]
},
{
"title": "💊 Steroids / Corticosteroids",
"data": [
["Brand Name", "Composition"],
["Dexona 0.5mg", "Dexamethasone"],
["Defcort 6 (DF2)", "Deflazacort 6mg"],
["Predmed / Medrol", "Methylprednisolone 4mg"],
["Wysolone 5/10/20", "Prednisolone dispersible"],
]
},
{
"title": "🧬 Vitamins / Supplements / Minerals",
"data": [
["Brand Name", "Composition"],
["Becosules", "B-complex vitamins"],
["Biozink HB", "Carbonyl iron 100 + Zinc sulphate monohydrate 61.8mg"],
["Cobanerve HR", "Methylcobalamin 1500mcg + Pyridoxine HCl 20mg + Folic acid 5mg"],
["D Rise (sachet)", "Cholecalciferol granules (Vit D3)"],
["Folvite", "Folic acid 5mg"],
["Kefcal", "Calcium carbonate + Vit D3"],
["Limcee", "Vitamin C (Ascorbic acid 500mg)"],
["Livogen", "Ferrous fumarate 152mg + Folic acid 1500mg"],
["Methylife HR", "Methylcobalamin 500mcg + Folic acid 5 + Vit B6 5mg"],
["Neurobion Forte", "Vitamin B complex"],
["Rejumet", "Methylcobalamine + Methcobalamin SR"],
["Urikind KM (powder)", "K Mg citrate + D-mannose + Cranberry extract"],
["Z&D 20", "Zinc dry powder (ZnS monohydrate 15mg)"],
]
},
{
"title": "🌀 Vertigo / Motion Sickness",
"data": [
["Brand Name", "Composition"],
["Betavert 16", "Betahistine 16mg"],
["Diziron", "Cinnarizine 25mg"],
["Vertin 8/16", "Betahistine"],
]
},
{
"title": "🚽 Urinary / Prostate / Bladder",
"data": [
["Brand Name", "Composition"],
["Alfoo 10", "Alfuzosin prolonged release 10mg"],
["Flavospas / Urispas", "Flavoxate 200mg"],
["Urikind KM", "K Mg citrate + D-mannose + Cranberry extract"],
]
},
{
"title": "🦟 Anti-malarial / Anti-inflammatory",
"data": [
["Brand Name", "Composition"],
["HCQS 200", "Hydroxychloroquine 200mg"],
]
},
{
"title": "🧫 Probiotics / Gut Flora",
"data": [
["Brand Name", "Composition"],
["Bifilac", "Probiotic combination"],
["Pre Pro Kid", "Lactobacillus rhamnosus + Saccharomyces boulardii"],
]
},
{
"title": "🪱 Antiparasitic / Anthelmintic",
"data": [
["Brand Name", "Composition"],
["Bandy 400", "Albendazole 400mg"],
]
},
{
"title": "👶 Paediatric Drops & Syrups",
"data": [
["Brand Name", "Composition"],
["Allercet Ped", "Cetirizine HCl 5mg dispersible"],
["Coriminic drops", "Phenylephrine HCl 5 + Chlorpheniramine maleate 2mg"],
["Colicacid drops", "Dill oil + Fennel oil + Simethicone (colic)"],
["Domstal Baby drops", "Domperidone 5mg/10ml"],
["Levolin 1mg syr", "Levosalbutamol syrup"],
["Montair LC Kid", "Montelukast Na 4 + Levocetirizine HCl 2.5mg"],
["cefixime 50 / 100 sus", "Cefixime 50mg / 100mg oral suspension"],
]
},
]
story = []
# Title
story.append(Paragraph("Medicine Reference Guide", title_style))
story.append(Paragraph("Organized by Disease / Condition Category", subtitle_style))
story.append(HRFlowable(width="100%", thickness=1.5, color=colors.HexColor('#1a3c6b')))
story.append(Spacer(1, 0.3*cm))
col_widths = [5.5*cm, 11.5*cm]
for idx, category in enumerate(categories):
color_hex = section_colors[idx % len(section_colors)]
bg_color = colors.HexColor(color_hex)
# Section header as a colored table row
header_table = Table(
[[Paragraph(category["title"], section_style)]],
colWidths=[17.0*cm]
)
header_table.setStyle(TableStyle([
('BACKGROUND', (0, 0), (-1, -1), bg_color),
('ROUNDEDCORNERS', [4, 4, 4, 4]),
('TOPPADDING', (0, 0), (-1, -1), 6),
('BOTTOMPADDING', (0, 0), (-1, -1), 6),
('LEFTPADDING', (0, 0), (-1, -1), 8),
]))
story.append(header_table)
story.append(Spacer(1, 0.1*cm))
# Data table
table_data = []
for row_idx, row in enumerate(category["data"]):
table_data.append([
Paragraph(row[0], normal_style),
Paragraph(row[1], normal_style)
])
t = Table(table_data, colWidths=col_widths)
style_cmds = [
('BACKGROUND', (0, 0), (-1, 0), colors.HexColor('#dce8f7')),
('TEXTCOLOR', (0, 0), (-1, 0), colors.HexColor('#1a3c6b')),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (-1, 0), 9),
('BOTTOMPADDING', (0, 0), (-1, 0), 5),
('TOPPADDING', (0, 0), (-1, 0), 5),
('ROWBACKGROUNDS', (0, 1), (-1, -1), [colors.white, colors.HexColor('#f5f9ff')]),
('FONTSIZE', (0, 1), (-1, -1), 8.5),
('TOPPADDING', (0, 1), (-1, -1), 4),
('BOTTOMPADDING', (0, 1), (-1, -1), 4),
('LEFTPADDING', (0, 0), (-1, -1), 6),
('RIGHTPADDING', (0, 0), (-1, -1), 6),
('GRID', (0, 0), (-1, -1), 0.4, colors.HexColor('#cccccc')),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
]
t.setStyle(TableStyle(style_cmds))
story.append(t)
story.append(Spacer(1, 0.3*cm))
doc.build(story)
print(f"PDF created: {output_path}")