Chemistry Paper Generator (Fixed Layout) /* --- 1. GLOBAL RESET --- */ * { box-sizing: border-box; } html, body { margin: 0; padding: 0; background-color: #525659; font-family: 'Times New Roman', serif; -webkit-print-color-adjust: exact; } /* --- 2. CONTROL DASHBOARD (Hidden in Print) --- */ #ui-dashboard { background: white; padding: 20px; max-width: 850px; margin: 20px auto; border-radius: 8px; border-top: 5px solid #198754; } .dash-row { display: flex; gap: 20px; margin-bottom: 15px; } .dash-group { flex: 1; } .dash-group label { display: block; font-weight: bold; margin-bottom: 5px; font-family: sans-serif; font-size: 14px; } .dash-group input, .dash-group select { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; } .btn-row { display: flex; gap: 10px; } button { flex: 1; padding: 10px; cursor: pointer; font-weight: bold; border: none; border-radius: 4px; color: white; } .btn-gen { background: #198754; } .btn-pdf { background: #0d6efd; } /* --- 3. PAPER CONTAINER (A4 Exact) --- */ #paper-container { width: 210mm; min-height: 297mm; height: auto; margin: 0 auto 50px auto; background: white; /* MARGINS HANDLED HERE TO FIX CUT-OFF */ padding: 15mm 12mm 15mm 12mm; position: relative; box-shadow: 0 0 10px rgba(0,0,0,0.5); } /* --- 4. BOARD HEADER --- */ .header-section { text-align: center; border-bottom: 3px double #000; padding-bottom: 8px; margin-bottom: 15px; width: 100%; } .inst-title { font-size: 22px; font-weight: 900; text-transform: uppercase; margin: 0; line-height: 1.1; } .exam-title { font-size: 16px; font-weight: bold; margin: 5px 0; text-transform: uppercase; } .meta-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-weight: bold; font-size: 14px; } .meta-table td { vertical-align: bottom; padding: 2px 0; } .roll-no-box { display: inline-block; width: 140px; height: 20px; border: 1px solid #000; vertical-align: bottom; margin-left: 5px; } /* --- 5. CONTENT STYLING --- */ .urdu-font { font-family: 'Noto Nastaliq Urdu', serif; direction: rtl; display: inline-block; margin-left: 8px; line-height: 1.4; } .section-bar { background: #000; color: #fff; padding: 4px 10px; font-weight: bold; font-size: 16px; margin: 15px 0 10px 0; display: flex; justify-content: space-between; } .sub-head { text-align: center; font-weight: bold; text-decoration: underline; margin: 15px 0 10px 0; font-size: 15px; } /* MCQs Layout */ .mcq-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; } .mcq-item { break-inside: avoid; border-bottom: 1px dashed #ccc; padding-bottom: 3px; margin-bottom: 8px; font-size: 13px; } .mcq-q { font-weight: bold; display: flex; justify-content: space-between; } .mcq-opts { display: flex; flex-wrap: wrap; justify-content: space-between; font-size: 12px; margin-top: 4px; } .mcq-opt { width: 48%; margin-bottom: 2px; } /* Subjective Layout */ .q-block { margin-bottom: 12px; break-inside: avoid; } .q-header { font-weight: bold; background: #f4f4f4; padding: 4px; border-left: 4px solid #000; font-size: 14px; } .short-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; } .short-item { border: 1px solid #ddd; padding: 5px; font-size: 13px; background: #fff; } .long-item { margin-bottom: 15px; border-bottom: 1px solid #000; padding-bottom: 8px; break-inside: avoid; } .long-part { display: flex; justify-content: space-between; margin-top: 4px; font-size: 14px; } /* KEY STYLES */ .key-separator { page-break-before: always; border-top: 2px dashed #000; margin-top: 20px; padding-top: 20px; } .key-title { text-align: center; font-weight: bold; font-size: 18px; text-decoration: underline; margin-bottom: 15px; } .key-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; text-align: center; } .key-box { border: 1px solid #000; padding: 5px; background: #eee; font-weight: bold; } /* --- 6. PRINT MEDIA --- */ @media print { body { background: white; } #ui-dashboard { display: none; } #paper-container { width: 100%; margin: 0; box-shadow: none; padding: 10mm; } } ⚗️ 9th Chemistry Paper Generator Institute Name: Paper Title: Paper Pattern: Full Paper (Obj + Subj) Objective Only Subjective Only Include Answer Key: No (Paper Only) Yes (With Answer Key) 🔄 Generate Paper 📄 Download PDF // ========================================== // 1. DATA (With Correct Index 'c': 0=A, 1=B...) // ========================================== const mcqs_db = [ { q: "Concentration of Nitrogen in air is:", u: "ہوا میں نائٹروجن کی مقدار ہے:", o: ["78%", "21%", "0.9%", "0.03%"], c: 0 }, { q: "Ozone layer protects earth from:", u: "اوزون لیئر زمین کو بچاتی ہے:", o: ["UV Rays", "IR Rays", "X-Rays", "Gamma Rays"], c: 0 }, { q: "pH of normal rain water is:", u: "عام بارش کے پانی کی pH ہے:", o: ["5.6-6.0", "7.0", "4.0", "8.0"], c: 0 }, { q: "Troposphere extends up to:", u: "ٹروپوسفیئر کی بلندی ہے:", o: ["12 km", "50 km", "85 km", "120 km"], c: 0 }, { q: "Which gas causes Global Warming?", u: "کون سی گیس گلوبل وارمنگ کا سبب ہے؟", o: ["CO2", "O2", "N2", "Ar"], c: 0 }, { q: "Primary pollutant is:", u: "پرائمری پولیوٹنٹ ہے:", o: ["SO2", "H2SO4", "O3", "HNO3"], c: 0 }, { q: "Effect of SO2 on marble is called:", u: "ماربل پر SO2 کا اثر کہلاتا ہے:", o: ["Stone Leprosy", "Corrosion", "Rusting", "None"], c: 0 }, { q: "Specific heat capacity of water:", u: "پانی کی سپیسیفک ہیٹ کپیسٹی ہے:", o: ["4.2 Jg-1K-1", "2.4 Jg-1K-1", "1.0 Jg-1K-1", "0.5 Jg-1K-1"], c: 0 }, { q: "Temporary hardness is removed by:", u: "عارضی ہارڈنس ختم کی جاتی ہے:", o: ["Boiling", "Clark's Method", "Both A & B", "None"], c: 2 }, { q: "Formula of Gypsum is:", u: "جپسم کا فارمولا ہے:", o: ["CaSO4.2H2O", "CaSO4.1/2H2O", "CuSO4.5H2O", "MgSO4"], c: 0 }, { q: "Cholera is caused by:", u: "ہیضہ کس کی وجہ سے ہوتا ہے؟", o: ["Bacteria", "Virus", "Fungi", "Algae"], c: 0 }, { q: "Which gas is used in swimming pools?", u: "سوئمنگ پول میں کون سی گیس استعمال ہوتی ہے؟", o: ["Chlorine", "Oxygen", "Nitrogen", "Helium"], c: 0 } ]; const short_db = [ { e: "Define Atmosphere.", u: "ایٹموسفیئر کی تعریف کریں۔" }, { e: "What is Ozone Hole?", u: "اوزون ہول کیا ہے؟" }, { e: "Define Pollutants.", u: "پولیوٹنٹس کی تعریف کریں۔" }, { e: "Differentiate between Soft & Hard Water.", u: "سافٹ اور ہارڈ واٹر میں فرق کریں۔" }, { e: "What is Leaching?", u: "لیچنگ کیا ہے؟" }, { e: "Define Fluorosis.", u: "فلوروسس کی تعریف کریں۔" }, { e: "How is CO2 beneficial for plants?", u: "پودوں کے لیے CO2 کیسے فائدہ مند ہے؟" }, { e: "What is Incineration?", u: "انسینریشن کیا ہے؟" }, { e: "Define Global Warming.", u: "گلوبل وارمنگ کی تعریف کریں۔" }, { e: "Effects of SO2 on health.", u: "صحت پر SO2 کے اثرات۔" } ]; const long_db = [ { a: "Explain the layers of Atmosphere.", u: "فضا کی تہوں کی وضاحت کریں۔" }, { b: "Describe Ozone Depletion.", u: "اوزون کے خاتمے پر نوٹ لکھیں۔" }, { a: "Explain methods to remove Permanent Hardness.", u: "مستقل ہارڈنس ختم کرنے کے طریقے لکھیں۔" }, { b: "Write a note on Waterborne Diseases.", u: "پانی سے پیدا ہونے والی بیماریوں پر نوٹ لکھیں۔" } ]; let currentMCQs = []; // Store current random MCQs for key generation // ========================================== // 2. LOGIC // ========================================== function generatePaper() { const container = document.getElementById('paper-container'); const inst = document.getElementById('inp-inst').value; const title = document.getElementById('inp-title').value; const type = document.getElementById('inp-type').value; const keyMode = document.getElementById('inp-key').value; let totalMarks = type === 'obj' ? 12 : (type === 'subj' ? 48 : 60); let time = type === 'obj' ? "20 Min" : (type === 'subj' ? "1:45 Hours" : "2:00 Hours"); let html = ` ${inst} ${title} Time Allowed: ${time} Total Marks: ${totalMarks} Date: ________________ Roll No: `; // PART I: OBJECTIVE if(type === 'full' || type === 'obj') { html += ` PART - I (Objective) Marks: 12 Q.1: Choose the correct answer. (12 x 1 = 12) `; // Randomize & Store currentMCQs = mcqs_db.sort(() => 0.5 - Math.random()).slice(0, 12); currentMCQs.forEach((m, i) => { html += ` ${i+1}. ${m.q} ${m.u} (A) ${m.o[0]} (B) ${m.o[1]} (C) ${m.o[2]} (D) ${m.o[3]} `; }); html += ``; } // PART II: SUBJECTIVE if(type === 'full' || type === 'subj') { html += ` PART - II (Subjective) Marks: 48 SECTION - I Note: Attempt any FIVE parts from each question. (5 x 2 = 10) `; const pool = [...short_db, ...short_db, ...short_db]; [2, 3, 4].forEach(num => { const qs = pool.sort(() => 0.5 - Math.random()).slice(0, 8); html += ` Q.${num}: Write short answers. `; qs.forEach((q, i) => { html += ` (${i+1}) ${q.e} ${q.u} `; }); html += ``; }); html += ` SECTION - II Note: Attempt any TWO questions. (9 x 2 = 18) `; [5, 6, 7].forEach((num, idx) => { const q = idx < long_db.length ? long_db[idx] : long_db[0]; html += ` Q.${num}: (a) ${q.a} (5) ${q.u} (b) ${q.b} (4) ${q.u} `; }); } // ANSWER KEY if(keyMode === 'yes' && (type === 'full' || type === 'obj')) { html += ``; html += `ANSWER KEY`; html += ``; const optLabels = ['A', 'B', 'C', 'D']; currentMCQs.forEach((m, i) => { html += `Q.${i+1}: ${optLabels[m.c]}`; }); html += ``; } container.innerHTML = html; } // ========================================== // 3. PDF DOWNLOAD (Zero Margin Fix) // ========================================== function downloadPDF() { const element = document.getElementById('paper-container'); const opt = { margin: 0, // FIXED: Set to 0 to prevent blank page. Layout controlled by CSS padding. filename: 'Chemistry-Paper.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, scrollY: 0 }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }, pagebreak: { mode: ['avoid-all', 'css', 'legacy'] } }; html2pdf().set(opt).from(element).save(); } window.onload = generatePaper;