Explain me antianginal drugs with its mechanism of action and side effects with diagrams
antianginal drugs mechanism of action diagram
nitrate mechanism angina vasodilation smooth muscle
calcium channel blocker mechanism cardiac angina
beta blocker mechanism of action heart rate angina
Antianginal drugs mechanism of action summary diagram showing four drug classes: 1) Organic Nitrates (nitroglycerin) - releases nitric oxide, activates guanylyl cyclase, increases cGMP, causes venodilation reducing preload and arterial dilation reducing afterload; 2) Beta-blockers (metoprolol, atenolol) - block beta-1 receptors, reduce heart rate and contractility, decrease myocardial oxygen demand; 3) Calcium Channel Blockers - divided into dihydropyridines (amlodipine, nifedipine) causing peripheral vasodilation, and non-dihydropyridines (verapamil, diltiazem) reducing heart rate and contractility; 4) Newer agents - Ranolazine blocks late sodium current, Ivabradine blocks If current in SA node. Central focus shows the oxygen supply-demand balance in the heart. Medical education style with clear labels and arrows.
Nitrate mechanism of action detailed biochemical pathway diagram: nitroglycerin enters smooth muscle cell, converted by ALDH2 enzyme and glutathione S-transferase, releases nitric oxide (NO), NO activates soluble guanylyl cyclase (sGC), converts GTP to cGMP, cGMP activates protein kinase G (PKG), PKG dephosphorylates myosin light chains, smooth muscle relaxation and vasodilation. Show venous dilation reducing preload and arterial dilation reducing afterload. Medical textbook illustration style with labeled pathways and arrows.
Comparison table diagram of antianginal drugs side effects: Organic Nitrates side effects (headache, flushing, hypotension, reflex tachycardia, tolerance with continuous use); Beta-blockers side effects (bradycardia, fatigue, bronchospasm, cold extremities, impotence, masking hypoglycemia); Calcium Channel Blockers - dihydropyridines side effects (peripheral edema, flushing, headache, reflex tachycardia) vs non-dihydropyridines (bradycardia, constipation, negative inotropy); Ranolazine side effects (QT prolongation, dizziness, constipation). Clean medical education infographic style with color-coded boxes per drug class.


| Effect | Result |
|---|---|
| Venodilation (dominant) | ↓ Venous return → ↓ Preload → ↓ Wall tension → ↓ O₂ demand |
| Arterial dilation | ↓ Afterload → ↓ Cardiac work |
| Coronary redistribution | Improves flow to ischemic subendocardium |
| Weak negative inotropy | via NO |
| Side Effect | Mechanism |
|---|---|
| Headache (most common) | Cerebral vasodilation |
| Flushing | Cutaneous vasodilation |
| Hypotension / syncope | Excessive vasodilation |
| Reflex tachycardia | Baroreceptor response to hypotension |
| Tolerance | Depletion of sulfhydryl groups needed for ALDH2; requires nitrate-free interval (8–12 h/day) |
| Severe hypotension with PDE-5 inhibitors | Both increase cGMP — dangerous combination; wait ≥6 h between use |
| Methemoglobinemia (with large doses) | Rare |
| Side Effect | Notes |
|---|---|
| Bradycardia / heart block | Especially non-selective agents |
| Bronchospasm | β₂ blockade — contraindicated in asthma |
| Fatigue, lethargy | CNS effects |
| Cold extremities | ↓ peripheral perfusion |
| Impotence | Peripheral vascular effect |
| Masking of hypoglycemia | Blocks tachycardia warning sign in diabetics |
| Rebound angina | On abrupt withdrawal — must taper |
| Negative inotropy | Worsens decompensated heart failure |
| Drug Class | Primary Target | Effect |
|---|---|---|
| Dihydropyridines | Vascular smooth muscle >> heart | Peripheral arterial vasodilation → ↓ afterload |
| Verapamil | Heart > vessels | ↓ HR, ↓ contractility, ↓ AV conduction; less vasodilation |
| Diltiazem | Heart and vessels equally | Intermediate effects |
| Side Effect | Cause |
|---|---|
| Peripheral edema | Vasodilation causing precapillary dilation > postcapillary |
| Flushing, headache | Vasodilation |
| Reflex tachycardia | With short-acting nifedipine (less with amlodipine) |
| Gingival hyperplasia | (especially nifedipine) |
| Side Effect | Cause |
|---|---|
| Bradycardia / AV block | Direct cardiac effect |
| Constipation | (especially verapamil — smooth muscle relaxation in GI) |
| Negative inotropy | May worsen systolic heart failure |
| Contraindicated with β-blockers | Risk of complete heart block |

| Drug Class | Key Mechanism | Reduces | Angina Type | Key Side Effect |
|---|---|---|---|---|
| Organic Nitrates | NO → cGMP → vasodilation | Preload (primarily) | Effort + Vasospastic | Headache, tolerance |
| β-Blockers | ↓ HR, contractility | O₂ demand | Effort only | Bronchospasm, bradycardia |
| DHP CCBs | Block L-Ca²⁺ in vessels | Afterload | Effort + Vasospastic | Edema, flushing |
| Non-DHP CCBs | Block L-Ca²⁺ in heart | HR + contractility | Effort + Vasospastic | AV block, constipation |
| Ranolazine | Block late I_Na | Diastolic tension | Effort (add-on) | QT prolongation |
| Ivabradine | Block I_f in SA node | HR only | Effort (add-on) | Visual phosphenes |
| Nicorandil | K⁺ activation + NO | Pre/afterload | Effort + Vasospastic | Headache, ulcers |
Key Clinical Point: β-blockers and short-acting dihydropyridine CCBs should not be combined (risk of severe bradycardia). However, β-blockers + long-acting DHPs (amlodipine) is a safe and effective combination. Never combine nitrates + PDE-5 inhibitors (sildenafil, tadalafil) due to severe hypotension risk.
Can you generate flashcards for it
ls -la /home/daytona/workspace/ 2>/dev/null || mkdir -p /home/daytona/workspace && echo "workspace ready"
mkdir -p /home/daytona/workspace/antianginal-flashcards && echo "dir created"
~/antianginal-flashcards/generate_flashcards.py
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.pdfgen import canvas
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import Paragraph
from reportlab.lib.enums import TA_CENTER, TA_LEFT
import textwrap
OUTPUT = "/home/daytona/workspace/antianginal-flashcards/Antianginal_Drugs_Flashcards.pdf"
# Flashcard data: (question, answer, category, color)
CARDS = [
# ── OVERVIEW ──────────────────────────────────────────────────────────────
(
"What is the fundamental mechanism of angina pectoris?",
"Imbalance between myocardial O₂ DEMAND and O₂ SUPPLY.\n\n"
"• Effort angina: demand exceeds supply during exertion\n"
"• Vasospastic (Prinzmetal): supply decreases due to coronary spasm\n"
"• Unstable angina: platelet clots + increased coronary resistance at rest",
"Overview", "#2C3E50"
),
(
"Name the 4 main classes of antianginal drugs.",
"1. Organic Nitrates (nitroglycerin, ISDN, ISMN)\n"
"2. Beta-blockers (metoprolol, atenolol, propranolol)\n"
"3. Calcium Channel Blockers (amlodipine, verapamil, diltiazem)\n"
"4. Newer agents (ranolazine, ivabradine, nicorandil, trimetazidine)",
"Overview", "#2C3E50"
),
# ── ORGANIC NITRATES ──────────────────────────────────────────────────────
(
"What is the mechanism of action of organic nitrates?",
"Nitrates → (ALDH2 / glutathione-S-transferase) → Nitric Oxide (NO)\n\n"
"NO activates soluble guanylyl cyclase (sGC)\n"
"sGC: GTP → cGMP\n"
"cGMP activates Protein Kinase G (PKG)\n"
"PKG dephosphorylates myosin light chains → smooth muscle relaxation → VASODILATION",
"Organic Nitrates", "#1A5276"
),
(
"What are the primary hemodynamic effects of nitrates in angina?",
"DOMINANT EFFECT — Venodilation:\n"
"↓ venous return → ↓ preload → ↓ ventricular wall tension → ↓ O₂ demand\n\n"
"SECONDARY — Arterial dilation:\n"
"↓ afterload → ↓ cardiac work → ↓ O₂ demand\n\n"
"Also: coronary redistribution to ischemic subendocardium\n"
"Weak negative inotropy via NO",
"Organic Nitrates", "#1A5276"
),
(
"Why is the sublingual route preferred for nitroglycerin?",
"Oral bioavailability is LOW (<10–20%) due to extensive hepatic first-pass metabolism.\n\n"
"Sublingual route BYPASSES first-pass effect:\n"
"• Onset: 1–3 minutes\n"
"• Duration: 15–30 minutes\n\n"
"Isosorbide mononitrate (ISMN) has 100% oral bioavailability (no first-pass effect).",
"Organic Nitrates", "#1A5276"
),
(
"What enzyme is key in activating nitroglycerin inside cells?",
"Mitochondrial ALDH2 (Aldehyde Dehydrogenase Isoform 2)\n\n"
"Also: glutathione S-transferase\n\n"
"These enzymes denitrate nitroglycerin → release of nitric oxide (NO)\n\n"
"Depletion of ALDH2 sulfhydryl groups is the primary mechanism of NITRATE TOLERANCE.",
"Organic Nitrates", "#1A5276"
),
(
"List the side effects of organic nitrates.",
"• Headache (most common) — cerebral vasodilation\n"
"• Flushing — cutaneous vasodilation\n"
"• Orthostatic hypotension / syncope\n"
"• Reflex tachycardia — baroreceptor response\n"
"• Tolerance — with continuous use; requires 8–12 h nitrate-free interval\n"
"• Severe hypotension if combined with PDE-5 inhibitors (sildenafil, tadalafil)\n"
"• Methemoglobinemia (rare, with large doses)",
"Organic Nitrates", "#1A5276"
),
(
"Why are nitrates contraindicated with PDE-5 inhibitors (sildenafil)?",
"Both increase cGMP levels:\n"
"• Nitrates: stimulate cGMP production (via NO → sGC)\n"
"• PDE-5 inhibitors: block cGMP BREAKDOWN\n\n"
"Combined effect = massive ↑ cGMP → severe, potentially fatal HYPOTENSION\n\n"
"Clinical rule: Wait ≥6 hours between a nitrate and a PDE-5 inhibitor.",
"Organic Nitrates", "#1A5276"
),
(
"How does nitrate tolerance develop and how is it prevented?",
"MECHANISM:\n"
"Continuous nitrate exposure depletes sulfhydryl groups (-SH)\n"
"→ ALDH2 cannot activate nitroglycerin → no NO release\n\n"
"PREVENTION:\n"
"• Provide a nitrate-free interval of 8–12 hours daily\n"
" (usually overnight when angina risk is lowest)\n"
"• Use eccentric dosing (e.g. ISMN: 8 AM and 3 PM, not equal intervals)",
"Organic Nitrates", "#1A5276"
),
# ── BETA-BLOCKERS ─────────────────────────────────────────────────────────
(
"What is the mechanism of beta-blockers in angina?",
"Block β₁-adrenoceptors on the heart:\n\n"
"↓ Heart rate (negative chronotropy)\n"
"↓ Contractility (negative inotropy)\n"
"↓ AV conduction velocity\n\n"
"→ ↓ Myocardial O₂ DEMAND (key: reduces rate-pressure product)\n"
"→ Prolongs diastolic filling time → better coronary perfusion\n\n"
"NOT vasodilators — ineffective (may worsen) vasospastic angina.",
"Beta-Blockers", "#117A65"
),
(
"Name cardioselective vs. non-selective beta-blockers used in angina.",
"CARDIOSELECTIVE (β₁ selective):\n"
"• Metoprolol, Atenolol, Bisoprolol\n"
"• Preferred in patients with asthma/COPD\n\n"
"NON-SELECTIVE (β₁ + β₂):\n"
"• Propranolol, Nadolol\n"
"• Block both cardiac and bronchial/vascular β receptors\n\n"
"Note: Cardioselectivity is RELATIVE, not absolute at high doses.",
"Beta-Blockers", "#117A65"
),
(
"List the side effects of beta-blockers.",
"• Bradycardia / AV block\n"
"• Bronchospasm — β₂ blockade (CONTRAINDICATED in asthma)\n"
"• Fatigue, lethargy (CNS effects)\n"
"• Cold extremities / worsened peripheral vascular disease\n"
"• Erectile dysfunction\n"
"• Masks hypoglycemia (blunts tachycardia warning) in diabetics\n"
"• Rebound angina on ABRUPT WITHDRAWAL — must taper\n"
"• Worsens decompensated heart failure (acute setting)\n"
"• Can worsen Prinzmetal (vasospastic) angina",
"Beta-Blockers", "#117A65"
),
(
"In which type of angina are beta-blockers CONTRAINDICATED?",
"VASOSPASTIC (Prinzmetal) angina\n\n"
"Reason: β-blockade removes sympathetic vasodilation\n"
"→ Unopposed α-adrenergic vasoconstriction\n"
"→ Coronary spasm WORSENED\n\n"
"First-line for vasospastic angina: Calcium Channel Blockers (especially dihydropyridines)\n"
"Also nitrates are effective.",
"Beta-Blockers", "#117A65"
),
# ── CALCIUM CHANNEL BLOCKERS ──────────────────────────────────────────────
(
"What is the general mechanism of calcium channel blockers in angina?",
"Block voltage-gated L-type (slow) Ca²⁺ channels:\n\n"
"In vascular smooth muscle:\n"
"↓ Ca²⁺ influx → vasodilation → ↓ afterload → ↓ O₂ demand\n\n"
"In cardiac muscle (non-DHPs):\n"
"↓ Ca²⁺ influx → ↓ HR, ↓ contractility, ↓ AV conduction → ↓ O₂ demand\n\n"
"Also dilate coronary arteries → ↑ O₂ supply\n"
"DRUG OF CHOICE for vasospastic (Prinzmetal) angina.",
"Calcium Channel Blockers", "#7D3C98"
),
(
"How do dihydropyridine CCBs differ from non-dihydropyridines?",
"DIHYDROPYRIDINES (amlodipine, nifedipine, felodipine):\n"
"• Act mainly on VASCULAR smooth muscle\n"
"• Potent peripheral vasodilation → ↓ afterload\n"
"• Can cause reflex tachycardia (especially short-acting nifedipine)\n"
"• Little/no direct cardiac effect\n\n"
"NON-DIHYDROPYRIDINES:\n"
"• Verapamil: Acts mainly on HEART (like β-blocker effect)\n"
"• Diltiazem: Intermediate — both heart and vessels\n"
"• Both slow HR and reduce contractility\n"
"• CONTRAINDICATED with β-blockers (risk of complete AV block)",
"Calcium Channel Blockers", "#7D3C98"
),
(
"List the side effects of dihydropyridine CCBs (e.g., amlodipine, nifedipine).",
"• Peripheral edema (ankle edema) — most common\n"
" (precapillary dilation > postcapillary)\n"
"• Flushing, headache — vasodilation\n"
"• Reflex tachycardia (more with short-acting nifedipine)\n"
"• Gingival hyperplasia (especially nifedipine)\n"
"• Dizziness, palpitations\n\n"
"NOTE: Amlodipine (long-acting) has much less reflex tachycardia than nifedipine.",
"Calcium Channel Blockers", "#7D3C98"
),
(
"List the side effects of non-dihydropyridine CCBs (verapamil, diltiazem).",
"VERAPAMIL:\n"
"• Bradycardia / AV block (most potent cardiac effect)\n"
"• Constipation (very common — smooth muscle relaxation in GI)\n"
"• Negative inotropy — may precipitate heart failure\n"
"• Hypotension\n\n"
"DILTIAZEM:\n"
"• Bradycardia, AV block (less than verapamil)\n"
"• Flushing, edema (less than DHPs)\n\n"
"BOTH: Contraindicated with β-blockers (risk of complete heart block)",
"Calcium Channel Blockers", "#7D3C98"
),
# ── RANOLAZINE ────────────────────────────────────────────────────────────
(
"What is the mechanism of action of ranolazine?",
"Inhibits the LATE sodium current (late I_Na)\n\n"
"↓ Na⁺ entry → ↓ Na⁺/Ca²⁺ exchanger activity → ↓ intracellular Ca²⁺\n"
"→ ↓ Diastolic tension and cardiac work → ↓ O₂ demand\n\n"
"Key features:\n"
"• Does NOT affect heart rate or blood pressure\n"
"• Used as ADD-ON therapy when standard drugs are insufficient\n"
"• Prolongs QT interval (but not associated with torsades de pointes)\n"
"• May inhibit metabolism of digoxin and simvastatin",
"Newer Agents", "#C0392B"
),
(
"What are the side effects and drug interactions of ranolazine?",
"Side effects:\n"
"• QT prolongation (monitor ECG)\n"
"• Dizziness, headache\n"
"• Constipation, nausea\n\n"
"Drug interactions:\n"
"• Inhibits metabolism of DIGOXIN → ↑ digoxin levels\n"
"• Inhibits metabolism of SIMVASTATIN → ↑ simvastatin levels\n\n"
"Unique: Shortens QT in LQT3 syndrome (despite prolonging in CAD patients)\n"
"Approved in USA for chronic stable angina.",
"Newer Agents", "#C0392B"
),
# ── IVABRADINE ────────────────────────────────────────────────────────────
(
"What is the mechanism of ivabradine?",
"Selectively blocks the hyperpolarization-activated I_f (\"funny\") current\n"
"in the SINOATRIAL (SA) node\n\n"
"→ ↓ Slope of pacemaker depolarization\n"
"→ ↓ Heart rate ONLY (pure rate reduction)\n\n"
"NO effect on:\n"
"• Blood pressure\n"
"• Contractility\n"
"• AV conduction\n"
"• Peripheral vasodilation\n\n"
"Similar efficacy to CCBs and β-blockers for angina prophylaxis.",
"Newer Agents", "#C0392B"
),
(
"What are the side effects of ivabradine?",
"• PHOSPHENES (visual disturbances) — flickering/enhanced brightness\n"
" in the visual field; due to If channels in retinal cells\n"
"• Bradycardia (dose-dependent)\n"
"• Headache\n\n"
"Important: Does NOT cause bronchospasm (unlike β-blockers)\n"
"Can be used in asthma patients who need rate control\n\n"
"Contraindicated in: sick sinus syndrome, severe bradycardia, AF",
"Newer Agents", "#C0392B"
),
# ── NICORANDIL ────────────────────────────────────────────────────────────
(
"What is the mechanism of nicorandil?",
"DUAL mechanism:\n\n"
"1. K⁺ channel activator (ATP-sensitive K⁺ channels)\n"
" → Membrane hyperpolarization → vascular smooth muscle relaxation\n"
" → Arterial and venous vasodilation\n\n"
"2. Nitrate-like NO donor component\n"
" → Additional vasodilation (similar to organic nitrates)\n\n"
"Result: ↓ Preload + ↓ Afterload + coronary vasodilation\n"
"Effective in both effort and vasospastic angina.",
"Newer Agents", "#C0392B"
),
(
"What are the side effects of nicorandil?",
"• Headache (common — nitrate component)\n"
"• Flushing\n"
"• Hypotension\n"
"• ORAL and GASTROINTESTINAL ULCERATION (distinctive side effect)\n"
" — may also cause perianal and skin ulcers\n"
"• Tolerance (less than pure nitrates)\n\n"
"Not approved in USA; used in Europe and Asia.",
"Newer Agents", "#C0392B"
),
# ── TRIMETAZIDINE ─────────────────────────────────────────────────────────
(
"What is the mechanism of trimetazidine?",
"Metabolic (pFOX) inhibitor:\n\n"
"Partially inhibits fatty acid oxidation by blocking\n"
"LC-3KAT (long-chain 3-ketoacyl thiolase)\n\n"
"→ Myocardium shifts from fatty acid oxidation to GLUCOSE oxidation\n"
"→ Glucose oxidation uses LESS O₂ per ATP generated\n"
"→ Improved metabolic efficiency in ischemic tissue\n\n"
"No effect on heart rate, blood pressure, or vasodilation.\n"
"NOT approved in the USA; available in Europe and Asia.",
"Newer Agents", "#C0392B"
),
# ── COMPARATIVE / HIGH-YIELD ──────────────────────────────────────────────
(
"Which drug is first-line for VASOSPASTIC (Prinzmetal) angina?",
"CALCIUM CHANNEL BLOCKERS (especially dihydropyridines like nifedipine)\n\n"
"• Directly relax coronary artery smooth muscle → relieve/prevent spasm\n\n"
"Also effective: Organic nitrates (sublingual GTN for acute relief)\n\n"
"AVOID: Beta-blockers\n"
"→ Remove sympathetic vasodilation → unopposed α-constriction → worsen spasm",
"Clinical Comparison", "#784212"
),
(
"Which antianginal drugs reduce heart rate?",
"Heart rate REDUCING agents:\n"
"• Beta-blockers (↓ HR via β₁ blockade)\n"
"• Non-DHP CCBs — Verapamil and Diltiazem (↓ SA node automaticity)\n"
"• Ivabradine (selective I_f blocker in SA node)\n\n"
"Heart rate INCREASING (reflex tachycardia):\n"
"• Short-acting DHP CCBs (e.g., immediate-release nifedipine)\n"
"• Organic nitrates (via baroreceptor reflex)",
"Clinical Comparison", "#784212"
),
(
"Which combination of antianginal drugs is DANGEROUS and why?",
"DANGEROUS COMBINATIONS:\n\n"
"1. Nitrates + PDE-5 inhibitors (sildenafil, tadalafil)\n"
" → Both ↑ cGMP → severe hypotension / MI\n"
" → Wait ≥6 hours between use\n\n"
"2. Beta-blockers + Non-DHP CCBs (verapamil/diltiazem)\n"
" → Additive negative chronotropy/inotropy\n"
" → Risk of complete AV block and severe bradycardia\n\n"
"SAFE combination:\n"
"Beta-blocker + Amlodipine (long-acting DHP CCB) — complementary effects",
"Clinical Comparison", "#784212"
),
(
"Which antianginal drugs reduce PRELOAD vs AFTERLOAD?",
"PRELOAD reduction (venodilation):\n"
"• Organic nitrates (primary effect)\n"
"• Nicorandil (partial)\n\n"
"AFTERLOAD reduction (arterial dilation):\n"
"• Dihydropyridine CCBs (primary effect)\n"
"• Organic nitrates (secondary effect)\n"
"• Nicorandil (partial)\n\n"
"BOTH preload AND afterload:\n"
"• Nicorandil, high-dose nitrates\n\n"
"NEITHER (pure O₂ demand reduction via HR/contractility):\n"
"• Beta-blockers, Non-DHP CCBs, Ivabradine, Ranolazine",
"Clinical Comparison", "#784212"
),
(
"What is the clinical significance of the rate-pressure product in angina?",
"Rate-Pressure Product (RPP) = Heart Rate × Systolic Blood Pressure\n\n"
"• Best correlate of MYOCARDIAL O₂ DEMAND\n"
"• Angina threshold = point where RPP triggers ischemia\n\n"
"Drugs that reduce RPP:\n"
"• Beta-blockers (↓ HR and BP)\n"
"• Non-DHP CCBs (↓ HR and BP)\n"
"• Nitrates (↓ BP, may reflexly ↑ HR)\n\n"
"Goal of therapy: Keep RPP below the ischemic threshold",
"Clinical Comparison", "#784212"
),
(
"Summarize all antianginal drugs in a quick comparison.",
"Drug Class | Mechanism | Reduces | Angina Type\n"
"Nitrates | NO→cGMP→vasodil | Preload↓ | Effort+Vasospastic\n"
"β-Blockers | β₁ blockade | HR+contract | Effort ONLY\n"
"DHP CCBs | L-Ca²⁺ (vessel) | Afterload↓ | Effort+Vasospastic\n"
"Non-DHP CCBs | L-Ca²⁺ (heart) | HR+contract | Effort+Vasospastic\n"
"Ranolazine | Late I_Na block | Diastol.ten | Effort (add-on)\n"
"Ivabradine | I_f block (SA) | HR only | Effort (add-on)\n"
"Nicorandil | K⁺ channel+NO | Pre+Afterld | Effort+Vasospastic\n"
"Trimetazidine | Fatty acid oxid↓ | O₂/ATP req | Effort (add-on)",
"Clinical Comparison", "#784212"
),
]
# ─────────────────────────────────────────────────────────────────────────────
# PAGE LAYOUT: 2 cards per A4 page (front + back on same page)
# Each card: ~13 cm tall, full A4 width
# Front = question (left half), Back = answer (right half)
# ─────────────────────────────────────────────────────────────────────────────
PAGE_W, PAGE_H = A4 # 595 x 842 pt
MARGIN = 1 * cm
CARD_W = (PAGE_W - 2 * MARGIN) / 2 - 0.3 * cm
CARD_H = (PAGE_H - 2 * MARGIN) / 2 - 0.3 * cm
GUTTER = 0.6 * cm
def draw_card(c, x, y, w, h, header, body, bg_color, is_question=True):
"""Draw a single flashcard at position (x,y) with given dimensions."""
# Background
c.setFillColor(colors.HexColor(bg_color))
c.roundRect(x, y, w, h, radius=8, fill=1, stroke=0)
# Header bar
header_h = 0.85 * cm
c.setFillColor(colors.HexColor("#FFFFFF") if is_question else colors.HexColor("#F0F0F0"))
c.setStrokeColor(colors.HexColor("#FFFFFF"))
c.roundRect(x, y + h - header_h, w, header_h, radius=4, fill=1, stroke=0)
# Label (Q / A)
label = "Q" if is_question else "A"
c.setFont("Helvetica-Bold", 10)
c.setFillColor(colors.HexColor(bg_color))
c.drawString(x + 0.3 * cm, y + h - header_h + 0.22 * cm, label)
# Header text (category)
c.setFont("Helvetica-Bold", 8)
c.setFillColor(colors.HexColor(bg_color))
c.drawString(x + 0.7 * cm, y + h - header_h + 0.22 * cm, header)
# Body text
text_x = x + 0.4 * cm
text_y = y + h - header_h - 0.35 * cm
text_w = w - 0.8 * cm
text_h_available = h - header_h - 0.5 * cm
c.setFillColor(colors.white)
# Word-wrap manually using reportlab text object
text_obj = c.beginText(text_x, text_y)
text_obj.setFont("Helvetica", 8.5)
text_obj.setFillColor(colors.white)
text_obj.setLeading(12)
lines = body.split('\n')
chars_per_line = int(text_w / (8.5 * 0.52)) # approx char width
for line in lines:
if line.strip() == '':
text_obj.textLine('')
continue
# Wrap long lines
wrapped = textwrap.wrap(line, width=chars_per_line) if len(line) > chars_per_line else [line]
for wl in wrapped:
text_obj.textLine(wl)
c.drawText(text_obj)
def generate_pdf(output_path, cards):
c = canvas.Canvas(output_path, pagesize=A4)
c.setTitle("Antianginal Drugs – Flashcards")
c.setAuthor("Orris Medical AI")
c.setSubject("Pharmacology – Antianginal Drugs")
# Title page
c.setFillColor(colors.HexColor("#2C3E50"))
c.rect(0, 0, PAGE_W, PAGE_H, fill=1, stroke=0)
c.setFillColor(colors.white)
c.setFont("Helvetica-Bold", 28)
c.drawCentredString(PAGE_W / 2, PAGE_H / 2 + 3 * cm, "ANTIANGINAL DRUGS")
c.setFont("Helvetica-Bold", 18)
c.drawCentredString(PAGE_W / 2, PAGE_H / 2 + 1.5 * cm, "Pharmacology Flashcards")
c.setFont("Helvetica", 12)
c.drawCentredString(PAGE_W / 2, PAGE_H / 2 + 0.3 * cm, "Mechanism of Action · Side Effects · Clinical Pearls")
# Color legend
categories = [
("Overview", "#2C3E50"),
("Organic Nitrates", "#1A5276"),
("Beta-Blockers", "#117A65"),
("Calcium Channel Blockers", "#7D3C98"),
("Newer Agents", "#C0392B"),
("Clinical Comparison", "#784212"),
]
legend_y = PAGE_H / 2 - 2 * cm
c.setFont("Helvetica-Bold", 10)
c.drawCentredString(PAGE_W / 2, legend_y, "Card Categories:")
legend_y -= 0.6 * cm
for cat, col in categories:
c.setFillColor(colors.HexColor(col))
c.roundRect(PAGE_W / 2 - 7 * cm, legend_y - 0.15 * cm, 3 * cm, 0.45 * cm, radius=3, fill=1, stroke=0)
c.setFillColor(colors.white)
c.setFont("Helvetica-Bold", 9)
c.drawCentredString(PAGE_W / 2 - 5.5 * cm, legend_y, cat)
legend_y -= 0.65 * cm
c.setFont("Helvetica", 9)
c.setFillColor(colors.HexColor("#BDC3C7"))
c.drawCentredString(PAGE_W / 2, 2 * cm, f"Total: {len(cards)} flashcards • Source: Katzung's Basic & Clinical Pharmacology, 16th Ed.")
c.showPage()
# Flashcard pages — 2 cards per page (Q on left, A on right)
card_positions = [
# row 0 (top)
(MARGIN, MARGIN + CARD_H + GUTTER),
# row 1 (bottom)
(MARGIN, MARGIN),
]
cards_per_page = 2
for page_start in range(0, len(cards), cards_per_page):
page_cards = cards[page_start: page_start + cards_per_page]
for i, (question, answer, category, color) in enumerate(page_cards):
cx, cy = card_positions[i]
# Question (left half)
draw_card(c, cx, cy, CARD_W, CARD_H,
f"#{page_start + i + 1} {category}", question, color, is_question=True)
# Answer (right half)
draw_card(c, cx + CARD_W + GUTTER, cy, CARD_W, CARD_H,
f"#{page_start + i + 1} ANSWER", answer, color, is_question=False)
# Cut lines
c.setStrokeColor(colors.HexColor("#CCCCCC"))
c.setLineWidth(0.3)
c.setDash(4, 4)
# Horizontal cut line
mid_y = MARGIN + CARD_H + GUTTER / 2
c.line(0.3 * cm, mid_y, PAGE_W - 0.3 * cm, mid_y)
# Vertical cut line
mid_x = MARGIN + CARD_W + GUTTER / 2
c.line(mid_x, 0.3 * cm, mid_x, PAGE_H - 0.3 * cm)
c.setDash()
c.showPage()
c.save()
print(f"PDF saved: {output_path} ({len(cards)} cards)")
generate_pdf(OUTPUT, CARDS)
cd /home/daytona/workspace/antianginal-flashcards && python generate_flashcards.py 2>&1
ls -lh /home/daytona/workspace/antianginal-flashcards/