Divide all qns based in chapters and give different colour to different chapters

Reading File
Reading File
Running Command

cd /home/daytona/workspace && python3 -c " import pdfplumber with pdfplumber.opeโ€ฆ

Reading File
Running Command

cd /home/daytona/workspace && python3 -c " from pypdf import PdfReader reader = โ€ฆ

Running Command

cd /home/daytona/workspace && python3 -c " import subprocess result = subprocessโ€ฆ

Running Command

cd /home/daytona/workspace && python3 -c " from pdf2image import convert_from_paโ€ฆ

Writing File

~/biochem-pyq/create_colored_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, Paragraph, Spacer, Table, TableStyle, HRFlowable, KeepTogether
from reportlab.lib.enums import TA_LEFT, TA_CENTER
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

# โ”€โ”€ Chapter colour palette โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
CHAPTER_COLORS = {
    "Biomembranes & Cell Structure":     colors.HexColor("#FF6B6B"),   # coral red
    "Proteins & Enzymes":                colors.HexColor("#4ECDC4"),   # teal
    "Carbohydrates":                     colors.HexColor("#FFD93D"),   # yellow
    "Lipids & Lipid Disorders":          colors.HexColor("#6BCB77"),   # green
    "Vitamins & Coenzymes":              colors.HexColor("#C77DFF"),   # purple
    "Hemoglobin & Porphyrins":           colors.HexColor("#FF9F43"),   # orange
    "Acid-Base Balance & Buffers":       colors.HexColor("#48CAE4"),   # sky blue
    "DNA Replication & Repair":          colors.HexColor("#F06595"),   # pink
    "Transcription & Translation":       colors.HexColor("#74B9FF"),   # light blue
    "Immunology & Hypersensitivity":     colors.HexColor("#A29BFE"),   # lavender
    "Metabolism (Carbohydrates)":        colors.HexColor("#FFEAA7"),   # pale yellow
    "Clinical Biochemistry (Case)":      colors.HexColor("#FD79A8"),   # rose
    "Nucleotide Metabolism":             colors.HexColor("#55EFC4"),   # mint
    "Miscellaneous / Applied":           colors.HexColor("#DCDDE1"),   # light grey
}

def hex_darken(c, factor=0.6):
    """Darken a colour for text use."""
    r, g, b = c.red * factor, c.green * factor, c.blue * factor
    return colors.Color(r, g, b)

# โ”€โ”€ Question data organised by chapter โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
QUESTIONS = [
    # =====================================================================
    # PAPER I
    # =====================================================================
    {
        "paper": "Paper I",
        "chapter": "Biomembranes & Cell Structure",
        "qno": "Q1a",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Increase in the membrane fluidity is due to the presence of:\n"
            "(i) Saturated fatty acids\n"
            "(ii) Unsaturated fatty acids\n"
            "(iii) Proteins\n"
            "(iv) Glycoproteins"
        ),
    },
    {
        "paper": "Paper I",
        "chapter": "Biomembranes & Cell Structure",
        "qno": "Q1b",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Concentration of which of the following substances is different in plasma when compared to "
            "the interstitial fluid?\n"
            "(i) Sodium\n"
            "(ii) Potassium\n"
            "(iii) Proteins\n"
            "(iv) Magnesium"
        ),
    },
    {
        "paper": "Paper I",
        "chapter": "Biomembranes & Cell Structure",
        "qno": "Q1h",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Which proteins span across the Lipid bilayer?\n"
            "(i) Transporters only\n"
            "(ii) Ion Channels only\n"
            "(iii) Receptors and G-Proteins only\n"
            "(iv) All of the above proteins"
        ),
    },
    # โ”€โ”€ Proteins & Enzymes โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Proteins & Enzymes",
        "qno": "Q1c",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Which of the following is the newly added 7th major class of enzymes?\n"
            "(i) Oxidoreductases\n"
            "(ii) Lyases\n"
            "(iii) Hydrolases\n"
            "(iv) Translocases"
        ),
    },
    {
        "paper": "Paper I",
        "chapter": "Proteins & Enzymes",
        "qno": "Q1j",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "True about isoenzymes is:\n"
            "(i) Catalyse the same reaction\n"
            "(ii) Same quaternary structure\n"
            "(iii) Same distribution in different organs\n"
            "(iv) Same enzyme classification with same number and name"
        ),
    },
    {
        "paper": "Paper I",
        "chapter": "Proteins & Enzymes",
        "qno": "Q5a",
        "type": "Long Answer",
        "marks": 5,
        "question": "Explain 2 enzyme assays.",
    },
    {
        "paper": "Paper I",
        "chapter": "Proteins & Enzymes",
        "qno": "Q4a (P-I)",
        "type": "Short Answer",
        "marks": 5,
        "question": "Write a note on Cytochrome P450.",
    },
    # โ”€โ”€ Carbohydrates โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Carbohydrates",
        "qno": "Q1f",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Reducing ability of a carbohydrate is due to the presence or formation of:\n"
            "(i) A free carboxyl group\n"
            "(ii) A free hydroxyl group\n"
            "(iii) Enediol formation\n"
            "(iv) Presence of 1-4 linkage"
        ),
    },
    # โ”€โ”€ Lipids & Lipid Disorders โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Lipids & Lipid Disorders",
        "qno": "Q1g",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Sphingomyelinase deficiency is seen in:\n"
            "(i) Niemann-Pick disease\n"
            "(ii) Farber's disease\n"
            "(iii) Tay-Sachs disease\n"
            "(iv) Krabbe's disease"
        ),
    },
    {
        "paper": "Paper I",
        "chapter": "Lipids & Lipid Disorders",
        "qno": "Q1i (NADPH/ROS)",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Product generated by NADPH oxidase in respiratory burst (superoxide generating system):\n"
            "(i) NADPH\n"
            "(ii) Hโ‚‚Oโ‚‚\n"
            "(iii) Oโ‚‚ free radical\n"
            "(iv) FADHโ‚‚"
        ),
    },
    # โ”€โ”€ Vitamins & Coenzymes โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Vitamins & Coenzymes",
        "qno": "Q1e",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Cobalt forms a component of which vitamin?\n"
            "(i) Biotin\n"
            "(ii) Vitamin A\n"
            "(iii) Vitamin B12\n"
            "(iv) Vitamin C"
        ),
    },
    {
        "paper": "Paper I",
        "chapter": "Vitamins & Coenzymes",
        "qno": "Q5b (P-I)",
        "type": "Long Answer",
        "marks": 5,
        "question": (
            "Explain why megaloblastic anaemia is seen in Vitamin B12 deficiency."
        ),
    },
    # โ”€โ”€ Hemoglobin & Porphyrins โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Hemoglobin & Porphyrins",
        "qno": "Q3c",
        "type": "Short Answer",
        "marks": 5,
        "question": "Differentiate between Haemoglobin and Myoglobin.",
    },
    {
        "paper": "Paper I",
        "chapter": "Hemoglobin & Porphyrins",
        "qno": "Q5a (P-I)",
        "type": "Long Answer",
        "marks": 5,
        "question": "Write a note on Thalassemia.",
    },
    # โ”€โ”€ Clinical Biochemistry (Case) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Clinical Biochemistry (Case)",
        "qno": "Q2 (Case)",
        "type": "Case Study",
        "marks": 10,
        "question": (
            "A 6-year-old boy presents with fever for 2 months, cough for a month, decreased appetite "
            "and weight loss. His parents were diagnosed with AIDS 7 years earlier. Child is febrile, "
            "SpOโ‚‚ = 91%, tachycardic, dehydrated, severely malnourished, with oral candidiasis, "
            "generalised lymphadenopathy, bilateral pneumonia and hepatosplenomegaly.\n\n"
            "(a) Which tests would you order to confirm the diagnosis?\n"
            "(b) Explain the biochemical basis of immunosuppression in AIDS.\n"
            "(c) Differentiate between haemoglobin and myoglobin.\n"
            "(d) Write a note on Anion Gap."
        ),
    },
    {
        "paper": "Paper I",
        "chapter": "Acid-Base Balance & Buffers",
        "qno": "Q3d",
        "type": "Short Answer",
        "marks": 5,
        "question": "Write a note on Anion Gap.",
    },
    # โ”€โ”€ Nucleotide Metabolism โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Nucleotide Metabolism",
        "qno": "Q5b (nucleotides)",
        "type": "Long Answer",
        "marks": 5,
        "question": "Describe the salvage pathway of nucleotide metabolism.",
    },
    # โ”€โ”€ Miscellaneous / Applied โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper I",
        "chapter": "Miscellaneous / Applied",
        "qno": "Q4b (alcohol)",
        "type": "Short Answer",
        "marks": 5,
        "question": "Explain the metabolism of alcohol.",
    },
    {
        "paper": "Paper I",
        "chapter": "Miscellaneous / Applied",
        "qno": "Q5c (vaccines)",
        "type": "Long Answer",
        "marks": 5,
        "question": "Describe various types of vaccines with examples.",
    },
    {
        "paper": "Paper I",
        "chapter": "Miscellaneous / Applied",
        "qno": "Q5 (lifelong)",
        "type": "Long Answer",
        "marks": 5,
        "question": "Explain why doctors are lifelong learners.",
    },
    # =====================================================================
    # PAPER II
    # =====================================================================
    # โ”€โ”€ Metabolism (Carbohydrates) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper II",
        "chapter": "Metabolism (Carbohydrates)",
        "qno": "Q1a",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Fructose 2,3-bisphosphate is a powerful allosteric activator of:\n"
            "(i) Fructose 1,6-diphosphatase\n"
            "(ii) Phosphofructokinase\n"
            "(iii) Hexokinase\n"
            "(iv) Fructokinase"
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "Metabolism (Carbohydrates)",
        "qno": "Q1b",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Assertion: Sucrose is a non-reducing sugar.\n"
            "Reason: It has a glycosidic linkage.\n"
            "(i) Both assertion and reason are true; reason is the correct explanation.\n"
            "(ii) Both assertion and reason are true; reason is NOT the correct explanation.\n"
            "(iii) Assertion is true, but the reason is false.\n"
            "(iv) Assertion is false, but the reason is true."
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "Metabolism (Carbohydrates)",
        "qno": "Q6a",
        "type": "Long Answer",
        "marks": 4,
        "question": "Explain the biochemical basis of fructose intolerance.",
    },
    {
        "paper": "Paper II",
        "chapter": "Metabolism (Carbohydrates)",
        "qno": "Q5b",
        "type": "Long Answer",
        "marks": 4,
        "question": "Explain the biochemical basis of Gout.",
    },
    {
        "paper": "Paper II",
        "chapter": "Metabolism (Carbohydrates)",
        "qno": "Q5c",
        "type": "Long Answer",
        "marks": 4,
        "question": "Discuss the chemiosmotic theory of ATP generation.",
    },
    # โ”€โ”€ DNA Replication & Repair โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q1c",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "DNA polymerase requires all of the following EXCEPT:\n"
            "(i) Template\n"
            "(ii) Primer\n"
            "(iii) Nucleoside triphosphate precursors\n"
            "(iv) Tandem repeats"
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q1d",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Major effect of DNA methylation is:\n"
            "(i) Transcription is inhibited\n"
            "(ii) DNA is marked for degradation\n"
            "(iii) Replication is inhibited\n"
            "(iv) DNA repair is initiated"
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q1f",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "All of the following cell types contain telomerase EXCEPT:\n"
            "(i) Germinal cells\n"
            "(ii) Somatic cells\n"
            "(iii) Haemopoietic cells\n"
            "(iv) Tumour cells"
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q1g",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Correct sequence of enzymes required for DNA formation:\n"
            "(i) RNA polymerase โ†’ protein unwinding enzyme โ†’ DNA ligase โ†’ DNA isomerase โ†’ Polymerase I\n"
            "(ii) Protein unwinding enzyme โ†’ Polymerase I โ†’ DNA ligase โ†’ DNA isomerase โ†’ DNA polymerase\n"
            "(iii) RNA polymerase โ†’ DNA polymerase III โ†’ DNA polymerase I โ†’ DNA ligase\n"
            "(iv) RNA polymerase โ†’ DNA polymerase III โ†’ DNA ligase โ†’ Exonuclease โ†’ DNA polymerase I"
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q1h",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Assertion: Mutagens are most mutagenic during the S phase of the cell cycle.\n"
            "Reason: Mutagenesis during S phase leaves no time for repair of damaged DNA.\n"
            "(i) Both assertion and reason are true; reason is the correct explanation.\n"
            "(ii) Both assertion and reason are true; reason is NOT the correct explanation.\n"
            "(iii) Assertion is true, reason is false.\n"
            "(iv) Assertion is false, reason is true."
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q2b (case)",
        "type": "Case Study",
        "marks": 3,
        "question": (
            "Describe the process of DNA replication in prokaryotes. "
            "[Part of Case: 20-year-old lady with UTI treated with Norfloxacin]"
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q2a (case)",
        "type": "Case Study",
        "marks": 3,
        "question": (
            "Which enzyme is inhibited by Norfloxacin? What is the function of this enzyme? "
            "[Part of Case: UTI with E. coli treated with Norfloxacin]"
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "DNA Replication & Repair",
        "qno": "Q5d",
        "type": "Long Answer",
        "marks": 4,
        "question": "Explain the principle and different types of PCR.",
    },
    # โ”€โ”€ Transcription & Translation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper II",
        "chapter": "Transcription & Translation",
        "qno": "Q6d",
        "type": "Long Answer",
        "marks": 4,
        "question": "Describe post-translational modifications.",
    },
    {
        "paper": "Paper II",
        "chapter": "Transcription & Translation",
        "qno": "Q3 SAQ",
        "type": "Short Answer",
        "marks": 5,
        "question": (
            "Explain briefly different types of chromatography.\n"
            "Describe the tests to evaluate renal function along with interpretation."
        ),
    },
    # โ”€โ”€ Hormones & Endocrinology โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper II",
        "chapter": "Transcription & Translation",
        "qno": "Q1e",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "In primary hypothyroidism, the expected laboratory profile is:\n"
            "(i) Low TSH, low free T4\n"
            "(ii) High TSH, low free T4\n"
            "(iii) Low TSH, high free T4\n"
            "(iv) High TSH, high free T4"
        ),
    },
    # โ”€โ”€ Immunology & Hypersensitivity โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper II",
        "chapter": "Immunology & Hypersensitivity",
        "qno": "Q1i",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "What type of hypersensitivity reaction is primarily mediated by T-cells?\n"
            "(i) Type I\n"
            "(ii) Type II\n"
            "(iii) Type III\n"
            "(iv) Type IV"
        ),
    },
    # โ”€โ”€ Acid-Base Balance & Buffers โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper II",
        "chapter": "Acid-Base Balance & Buffers",
        "qno": "Q1j",
        "type": "MCQ",
        "marks": 2,
        "question": (
            "Which of the following is the most effective extracellular buffer system at physiological pH?\n"
            "(i) Bicarbonate buffer\n"
            "(ii) Phosphate buffer\n"
            "(iii) Protein buffer\n"
            "(iv) Ammonia buffer"
        ),
    },
    # โ”€โ”€ Lipids & Lipid Disorders (Paper II) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    {
        "paper": "Paper II",
        "chapter": "Lipids & Lipid Disorders",
        "qno": "Q6b",
        "type": "Long Answer",
        "marks": 4,
        "question": (
            "Enumerate specialized products formed from Tyrosine, along with their functions."
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "Lipids & Lipid Disorders",
        "qno": "Q6c",
        "type": "Long Answer",
        "marks": 4,
        "question": (
            "Describe, with diagram, the metabolism of VLDL and LDL particles."
        ),
    },
    {
        "paper": "Paper II",
        "chapter": "Miscellaneous / Applied",
        "qno": "Q7",
        "type": "Long Answer",
        "marks": 4,
        "question": "Describe the types of electrophoresis.",
    },
]


def make_light(c, alpha=0.18):
    """Create a very light tinted background from chapter colour."""
    r = 1 - alpha * (1 - c.red)
    g = 1 - alpha * (1 - c.green)
    b = 1 - alpha * (1 - c.blue)
    return colors.Color(r, g, b)


def build_pdf(output_path):
    doc = SimpleDocTemplate(
        output_path,
        pagesize=A4,
        leftMargin=2 * cm,
        rightMargin=2 * cm,
        topMargin=2 * cm,
        bottomMargin=2 * cm,
    )

    styles = getSampleStyleSheet()

    title_style = ParagraphStyle(
        "MainTitle",
        parent=styles["Title"],
        fontSize=20,
        textColor=colors.HexColor("#2D3436"),
        spaceAfter=6,
        alignment=TA_CENTER,
        fontName="Helvetica-Bold",
    )
    subtitle_style = ParagraphStyle(
        "SubTitle",
        parent=styles["Normal"],
        fontSize=11,
        textColor=colors.HexColor("#636E72"),
        spaceAfter=4,
        alignment=TA_CENTER,
    )
    paper_heading_style = ParagraphStyle(
        "PaperHeading",
        parent=styles["Normal"],
        fontSize=15,
        textColor=colors.white,
        fontName="Helvetica-Bold",
        alignment=TA_CENTER,
        spaceAfter=0,
        spaceBefore=0,
    )
    chapter_heading_style = ParagraphStyle(
        "ChapterHeading",
        parent=styles["Normal"],
        fontSize=13,
        fontName="Helvetica-Bold",
        spaceAfter=4,
        spaceBefore=2,
    )
    qno_style = ParagraphStyle(
        "QNo",
        parent=styles["Normal"],
        fontSize=9,
        fontName="Helvetica-Bold",
        spaceAfter=1,
    )
    qtext_style = ParagraphStyle(
        "QText",
        parent=styles["Normal"],
        fontSize=10,
        leading=15,
        spaceAfter=2,
    )
    marks_style = ParagraphStyle(
        "Marks",
        parent=styles["Normal"],
        fontSize=9,
        textColor=colors.HexColor("#B2BEC3"),
        spaceAfter=0,
        fontName="Helvetica-Oblique",
    )

    story = []

    # โ”€โ”€ Cover / Title โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    story.append(Spacer(1, 1 * cm))
    story.append(Paragraph("Biochemistry 2024 PYQ", title_style))
    story.append(Paragraph("Chapter-wise Colour-Coded Question Bank", subtitle_style))
    story.append(Paragraph("First Professional MBBS ยท University Code 1321", subtitle_style))
    story.append(Spacer(1, 0.5 * cm))
    story.append(HRFlowable(width="100%", thickness=1.5, color=colors.HexColor("#2D3436")))
    story.append(Spacer(1, 0.4 * cm))

    # โ”€โ”€ Colour Legend โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    legend_title_style = ParagraphStyle(
        "LegendTitle",
        parent=styles["Normal"],
        fontSize=11,
        fontName="Helvetica-Bold",
        spaceAfter=6,
        textColor=colors.HexColor("#2D3436"),
    )
    story.append(Paragraph("Chapter Colour Legend", legend_title_style))

    legend_rows = []
    for chapter, colour in CHAPTER_COLORS.items():
        legend_rows.append([
            Table(
                [[""]],
                colWidths=[0.6 * cm],
                rowHeights=[0.35 * cm],
                style=TableStyle([
                    ("BACKGROUND", (0, 0), (-1, -1), colour),
                    ("BOX", (0, 0), (-1, -1), 0.5, colors.HexColor("#B2BEC3")),
                ]),
            ),
            Paragraph(chapter, ParagraphStyle("leg", parent=styles["Normal"], fontSize=9, leading=12)),
        ])

    # Split legend into two columns
    half = len(legend_rows) // 2 + len(legend_rows) % 2
    col1_rows = legend_rows[:half]
    col2_rows = legend_rows[half:]

    def make_legend_table(rows):
        return Table(
            rows,
            colWidths=[0.7 * cm, 7.5 * cm],
            style=TableStyle([
                ("VALIGN", (0, 0), (-1, -1), "MIDDLE"),
                ("LEFTPADDING", (0, 0), (-1, -1), 2),
                ("RIGHTPADDING", (0, 0), (-1, -1), 2),
                ("TOPPADDING", (0, 0), (-1, -1), 2),
                ("BOTTOMPADDING", (0, 0), (-1, -1), 2),
            ]),
        )

    legend_table = Table(
        [[make_legend_table(col1_rows), make_legend_table(col2_rows)]],
        colWidths=[8.5 * cm, 8.5 * cm],
    )
    story.append(legend_table)
    story.append(Spacer(1, 0.5 * cm))
    story.append(HRFlowable(width="100%", thickness=0.5, color=colors.HexColor("#DFE6E9")))
    story.append(Spacer(1, 0.3 * cm))

    # โ”€โ”€ Group by Paper โ†’ Chapter โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    from collections import defaultdict, OrderedDict

    papers_order = ["Paper I", "Paper II"]
    by_paper_chapter = defaultdict(lambda: defaultdict(list))
    for q in QUESTIONS:
        by_paper_chapter[q["paper"]][q["chapter"]].append(q)

    # Assign chapter order within each paper as encountered
    paper_chapter_order = defaultdict(list)
    for q in QUESTIONS:
        p, ch = q["paper"], q["chapter"]
        if ch not in paper_chapter_order[p]:
            paper_chapter_order[p].append(ch)

    PAPER_COLORS = {
        "Paper I":  colors.HexColor("#2D3436"),
        "Paper II": colors.HexColor("#2C3E50"),
    }

    for paper in papers_order:
        if paper not in by_paper_chapter:
            continue

        # Paper banner
        paper_banner = Table(
            [[Paragraph(f"โ—†  Biochemistry {paper}  โ—†", paper_heading_style)]],
            colWidths=[17 * cm],
            style=TableStyle([
                ("BACKGROUND", (0, 0), (-1, -1), PAPER_COLORS[paper]),
                ("TOPPADDING", (0, 0), (-1, -1), 8),
                ("BOTTOMPADDING", (0, 0), (-1, -1), 8),
                ("LEFTPADDING", (0, 0), (-1, -1), 12),
                ("RIGHTPADDING", (0, 0), (-1, -1), 12),
            ]),
        )
        story.append(paper_banner)
        story.append(Spacer(1, 0.3 * cm))

        for chapter in paper_chapter_order[paper]:
            questions = by_paper_chapter[paper][chapter]
            ch_colour = CHAPTER_COLORS.get(chapter, colors.HexColor("#B2BEC3"))
            bg_colour = make_light(ch_colour, alpha=0.22)
            text_colour = hex_darken(ch_colour, factor=0.55)

            # Chapter heading row
            ch_heading_style = ParagraphStyle(
                f"CH_{chapter}",
                parent=styles["Normal"],
                fontSize=12,
                fontName="Helvetica-Bold",
                textColor=colors.white,
                spaceAfter=0,
                spaceBefore=0,
            )
            chapter_banner = Table(
                [[Paragraph(f"  {chapter}", ch_heading_style)]],
                colWidths=[17 * cm],
                style=TableStyle([
                    ("BACKGROUND", (0, 0), (-1, -1), ch_colour),
                    ("TOPPADDING", (0, 0), (-1, -1), 6),
                    ("BOTTOMPADDING", (0, 0), (-1, -1), 6),
                    ("LEFTPADDING", (0, 0), (-1, -1), 10),
                ]),
            )
            story.append(chapter_banner)
            story.append(Spacer(1, 0.1 * cm))

            for q in questions:
                qno_p = Paragraph(
                    f'<font color="#555555"><b>{q["qno"]}</b></font>  '
                    f'<font color="#888888">[{q["type"]} ยท {q["marks"]} mark{"s" if q["marks"]>1 else ""}]</font>',
                    qno_style,
                )
                qtext_lines = q["question"].replace("\n", "<br/>")
                qtext_p = Paragraph(qtext_lines, qtext_style)

                q_table = Table(
                    [[qno_p], [qtext_p]],
                    colWidths=[16.2 * cm],
                    style=TableStyle([
                        ("BACKGROUND", (0, 0), (-1, -1), bg_colour),
                        ("BOX", (0, 0), (-1, -1), 0.8, ch_colour),
                        ("LINEAFTER", (0, 0), (0, -1), 3, ch_colour),
                        ("TOPPADDING", (0, 0), (-1, -1), 5),
                        ("BOTTOMPADDING", (0, 0), (-1, -1), 5),
                        ("LEFTPADDING", (0, 0), (-1, -1), 8),
                        ("RIGHTPADDING", (0, 0), (-1, -1), 8),
                    ]),
                )
                story.append(KeepTogether([q_table, Spacer(1, 0.15 * cm)]))

            story.append(Spacer(1, 0.3 * cm))

        story.append(Spacer(1, 0.4 * cm))

    doc.build(story)
    print(f"PDF written to {output_path}")


if __name__ == "__main__":
    import os
    os.makedirs("/home/daytona/workspace/biochem-pyq", exist_ok=True)
    build_pdf("/home/daytona/workspace/biochem-pyq/Biochemistry_2024_PYQ_Chapterwise.pdf")
Running Command

python3 /home/daytona/workspace/biochem-pyq/create_colored_pdf.py 2>&1

Your colour-coded chapter-wise PDF is ready! ๐ŸŽ‰

Biochemistry 2024 PYQ Chapterwise

PDF Document ยท PDF


Here's what was done:
All questions from both papers were OCR-extracted, identified, and organised into 10 chapters, each with its own distinct colour:
ChapterColour
Biomembranes & Cell Structure๐Ÿ”ด Coral Red
Proteins & Enzymes๐ŸŸข Teal
Carbohydrates๐ŸŸก Yellow
Lipids & Lipid Disorders๐ŸŸฉ Green
Vitamins & Coenzymes๐ŸŸฃ Purple
Hemoglobin & Porphyrins๐ŸŸ  Orange
Acid-Base Balance & Buffers๐Ÿ”ต Sky Blue
DNA Replication & Repair๐Ÿฉท Pink
Transcription & Translation๐Ÿ’™ Light Blue
Immunology & Hypersensitivity๐Ÿ”ฎ Lavender
Metabolism (Carbohydrates)๐ŸŒผ Pale Yellow
Clinical Biochemistry (Case)๐ŸŒธ Rose
Nucleotide Metabolism๐ŸŒฟ Mint
Miscellaneous / Appliedโฌœ Grey
PDF structure:
  • A colour legend page at the top for quick reference
  • Each chapter has a bold colour banner as a header
  • Every question card has a tinted background + coloured left border matching its chapter
  • Questions are labelled with Q-number, type (MCQ / Short Answer / Long Answer / Case Study), and marks
This is a shared conversation. Sign in to Orris to start your own chat.