ÿþ<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Class XII Chemistry Sample Paper Generator</title> <link href="img/logo1.jpg" rel="icon"> <!-- Add jsPDF library --> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> :root { --primary: #4361ee; --primary-dark: #3f37c9; --secondary: #4895ef; --danger: #f72585; --success: #4cc9f0; --light: #f8f9fa; --dark: #212529; --gray: #6c757d; --border-radius: 12px; --box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); --transition: all 0.3s ease; } * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } body { background: linear-gradient(135deg, #f5f7fa 0%, #e2e8f0 100%); min-height: 100vh; display: flex; justify-content: center; align-items: center; padding: 20px; color: var(--dark); line-height: 1.6; } .container { width: 100%; max-width: 900px; background: white; border-radius: var(--border-radius); box-shadow: var(--box-shadow); overflow: hidden; transition: var(--transition); animation: fadeIn 0.5s ease-out; } @keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } } .header { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; padding: 30px 20px; text-align: center; position: relative; overflow: hidden; } .header::before { content: ''; position: absolute; top: -50px; right: -50px; width: 150px; height: 150px; background: rgba(255, 255, 255, 0.1); border-radius: 50%; } .header h1 { font-size: 2rem; margin-bottom: 10px; font-weight: 700; position: relative; z-index: 1; } .header p { font-size: 1rem; opacity: 0.9; position: relative; z-index: 1; } .content-area { padding: 30px; } .hidden { display: none !important; } .btn { display: inline-block; padding: 12px 28px; border-radius: 50px; font-weight: 600; cursor: pointer; transition: var(--transition); border: none; text-align: center; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); margin: 10px 5px; } .btn-primary { background: var(--primary); color: white; } .btn-primary:hover { background: var(--primary-dark); transform: translateY(-2px); box-shadow: 0 8px 15px rgba(67, 97, 238, 0.3); } .btn-success { background: var(--success); color: white; } .btn-success:hover { background: #3ab0d6; transform: translateY(-2px); box-shadow: 0 8px 15px rgba(76, 201, 240, 0.3); } .btn-danger { background: var(--danger); color: white; } .btn-danger:hover { background: #d3166b; transform: translateY(-2px); box-shadow: 0 8px 15px rgba(247, 37, 133, 0.3); } .btn-group { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 20px 0; } .section-title { text-align: center; margin-bottom: 25px; color: var(--primary-dark); font-size: 1.5rem; position: relative; padding-bottom: 10px; } .section-title::after { content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 80px; height: 3px; background: var(--secondary); border-radius: 3px; } .checkbox-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; margin: 25px 0; } .checkbox-item { display: flex; align-items: center; } .checkbox-item input { margin-right: 10px; width: 18px; height: 18px; cursor: pointer; } .checkbox-item label { cursor: pointer; font-size: 0.95rem; } .generated-paper { padding: 30px; } .paper-header { text-align: center; margin-bottom: 30px; border-bottom: 2px solid var(--primary); padding-bottom: 20px; } .paper-header h2 { color: var(--primary-dark); margin-bottom: 5px; font-size: 1.8rem; } .paper-header h3 { color: var(--gray); margin-bottom: 5px; font-size: 1.2rem; font-weight: 500; } .paper-meta { display: flex; justify-content: space-between; margin-bottom: 25px; padding-bottom: 15px; border-bottom: 1px solid #eee; font-weight: 500; } .instructions { margin-bottom: 30px; padding: 20px; background: #f8f9fa; border-radius: var(--border-radius); } .instructions ol { padding-left: 20px; margin-top: 10px; } .instructions li { margin-bottom: 8px; } .question-section { margin-bottom: 30px; } .section-heading { font-weight: 600; color: var(--primary-dark); margin-bottom: 15px; padding-bottom: 5px; border-bottom: 1px solid #eee; } .question { margin-bottom: 20px; page-break-inside: avoid; } .question-text { font-weight: 500; margin-bottom: 8px; } .option { margin-left: 20px; margin-bottom: 5px; } .action-buttons { display: flex; justify-content: center; flex-wrap: wrap; gap: 15px; margin-top: 40px; } @media (max-width: 768px) { .header h1 { font-size: 1.6rem; } .content-area { padding: 20px; } .checkbox-container { grid-template-columns: 1fr; } .btn { padding: 10px 20px; font-size: 0.9rem; } .paper-header h2 { font-size: 1.4rem; } .paper-header h3 { font-size: 1rem; } } @media (max-width: 480px) { .header { padding: 20px 15px; } .section-title { font-size: 1.3rem; } .paper-meta { flex-direction: column; gap: 10px; } .action-buttons { flex-direction: column; align-items: center; } .btn { width: 100%; max-width: 250px; } } @media print { body { background: none; padding: 0; } .container { box-shadow: none; max-width: 100%; } .action-buttons { display: none; } .question { page-break-inside: avoid; } } </style> <style> /* Ensure header styling is preserved */ .header { background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important; color: white !important; padding: 30px 20px !important; text-align: center !important; position: relative !important; overflow: hidden !important; width: 100% !important; } .header h1, .header h2, .header h3 { color: white !important; font-weight: bold !important; } .temp-pdf-container { font-family: Arial, sans-serif; line-height: 1.5; } .temp-pdf-container * { max-width: 100% !important; background-color: white !important; color: black !important; } /* Page break control */ .question { page-break-inside: avoid; break-inside: avoid; } .question-section { page-break-after: auto; } @media print { body { margin: 0 !important; padding: 0 !important; background: white !important; } .container { width: 100% !important; margin: 0 !important; padding: 0 !important; box-shadow: none !important; } .header { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; } } /* Home icon styles */ .home-icon { position: absolute; top: 20px; left: 20px; color: white; font-size: 24px; cursor: pointer; transition: var(--transition); z-index: 2; } .home-icon:hover { transform: scale(1.1); color: rgba(255, 255, 255, 0.8); } @media (max-width: 480px) { .home-icon { font-size: 20px; top: 15px; left: 15px; } } @media print { .home-icon { display: none; } } </style> </head> <body> <div class="container" id="startContainer"> <div class="header"> <!-- Home icon added here --> <a href="cbse-class-9-to-12-exam-paper-generator.html" class="home-icon"> <i class="fas fa-home"></i> </a> <h1>Class XII Chemistry</h1> <p>Generate Customized Sample Papers</p> </div> <div class="content-area"> <div id="startScreen"> <h2 class="section-title">Chemistry Paper Generator</h2> <div class="btn-group"> <button class="btn btn-primary" onclick="showChapterSelection()">Start Generating</button> </div> </div> <div id="chapterSelection" class="hidden"> <h2 class="section-title">Select Chapters for Chemistry</h2> <form id="chapterForm"> <div class="checkbox-container"> <div class="checkbox-item"> <input type="checkbox" id="fullPaper" name="chapter" value="Full Paper" onchange="toggleChapters()"> <label for="fullPaper">Full Paper (All Chapters)</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter1" name="chapter" value="Chapter 1"> <label for="chapter1">1. The Solid State</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter2" name="chapter" value="Chapter 2"> <label for="chapter2">2. Solutions</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter3" name="chapter" value="Chapter 3"> <label for="chapter3">3. Electrochemistry</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter4" name="chapter" value="Chapter 4"> <label for="chapter4">4. Chemical Kinetics</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter5" name="chapter" value="Chapter 5"> <label for="chapter5">5. Surface Chemistry</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter6" name="chapter" value="Chapter 6"> <label for="chapter6">6. General Principles and Processes of Isolation of Elements</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter7" name="chapter" value="Chapter 7"> <label for="chapter7">7. The p-Block Elements</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter8" name="chapter" value="Chapter 8"> <label for="chapter8">8. The d and f Block Elements</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter9" name="chapter" value="Chapter 9"> <label for="chapter9">9. Coordination Compounds</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter10" name="chapter" value="Chapter 10"> <label for="chapter10">10. Haloalkanes and Haloarenes</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter11" name="chapter" value="Chapter 11"> <label for="chapter11">11. Alcohols, Phenols and Ethers</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter12" name="chapter" value="Chapter 12"> <label for="chapter12">12. Aldehydes, Ketones and Carboxylic Acids</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter13" name="chapter" value="Chapter 13"> <label for="chapter13">13. Organic Compounds Containing Nitrogen (Amines)</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter14" name="chapter" value="Chapter 14"> <label for="chapter14">14. Biomolecules</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter15" name="chapter" value="Chapter 15"> <label for="chapter15">15. Polymers</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter16" name="chapter" value="Chapter 16"> <label for="chapter16">16. Chemistry in Everyday Life</label> </div> </div> </form> <div id="message" class="hidden"></div> <div class="btn-group"> <button class="btn btn-danger" onclick="backToStart()">Back to Start</button> <button class="btn btn-success" onclick="promptSchoolName()">Generate Paper</button> </div> </div> </div> </div> <div class="container hidden" id="generatedPaperContainer"></div> <script> // Initialize jsPDF const { jsPDF } = window.jspdf; let schoolName = ''; let questionCounter = 1; let sessionYear = ''; const questions = { chemistry: { "Chapter 1": { mcq: [ { question: "Which of the following is an example of amorphous solid?", options: ["Quartz", "Glass", "Diamond", "Graphite"], answer: "Glass" }, { question: "The coordination number in a body-centered cubic (BCC) structure is:", options: ["4", "6", "8", "12"], answer: "8" }, { question: "Which type of point defect is shown by NaCl when heated with Na vapor?", options: ["Schottky defect", "Frenkel defect", "Metal excess defect", "Metal deficiency defect"], answer: "Metal excess defect" }, { question: "In a face-centered cubic unit cell, the number of atoms per unit cell is:", options: ["1", "2", "4", "6"], answer: "4" }, { question: "Which of the following is a molecular solid?", options: ["SiO‚ ", "I‚ ", "NaCl", "MgO"], answer: "I‚ " } ], assertion: [ { statement1: "Amorphous solids are isotropic in nature.", statement2: "Amorphous solids have short range order only.", options: ["Both true", "Both false", "Only statement 1 is true", "Only statement 2 is true"], answer: "Both true" }, { statement1: "Doping of silicon with arsenic leads to n-type semiconductor.", statement2: "n-type semiconductors have excess of electrons.", options: ["Both true", "Both false", "Only statement 1 is true", "Only statement 2 is true"], answer: "Both true" } ], twoMark: [ "Differentiate between crystalline and amorphous solids.", "Calculate the number of atoms in a unit cell of a face-centered cubic structure.", "What are Schottky and Frenkel defects?", "Explain how doping increases the conductivity of semiconductors." ], threeMark: [ "Explain the types of voids in close packing of spheres.", "Describe the electrical properties of solids with examples.", "What are the differences between isotropic and anisotropic substances?" ], fiveMark: [ "Explain the different types of crystalline solids with examples.", "Describe the packing efficiency in different types of cubic unit cells.", "Discuss the various types of defects in crystals." ], caseStudy: [ { case: "A student was studying the properties of different types of solids. He observed that some solids melt at a sharp temperature while others soften over a range of temperatures. Some solids conduct electricity in molten state but not in solid state, while others conduct electricity in solid state.", questions: ["Classify the solids based on melting behavior.", "Identify which solids conduct electricity in molten state.", "What type of solids conduct electricity in solid state?"] } ] }, "Chapter 2": { mcq: [ { question: "Which of the following is not a colligative property?", options: ["Osmotic pressure", "Lowering of vapor pressure", "Elevation in boiling point", "Surface tension"], answer: "Surface tension" }, { question: "The mole fraction of solute in a 1 molal aqueous solution is:", options: ["0.0177", "0.0344", "0.5", "1"], answer: "0.0177" }, { question: "Which of the following solutions has the highest boiling point?", options: ["0.1 M glucose", "0.1 M NaCl", "0.1 M BaCl‚ ", "0.1 M AlClƒ "], answer: "0.1 M AlClƒ " }, { question: "Henry's law constant for CO‚ in water is 1.67×10x Pa at 298 K. The solubility of CO‚ when its partial pressure is 2.5 atm is:", options: ["1.52×10{ t mol/L", "2.5×10{ t mol/L", "4.17×10{ t mol/L", "6.68×10{ t mol/L"], answer: "1.52×10{ t mol/L" }, { question: "An ideal solution is formed when its components have:", options: ["”Hmix = 0, ”Vmix = 0", "”Hmix > 0, ”Vmix = 0", "”Hmix < 0, ”Vmix > 0", "”Hmix > 0, ”Vmix > 0"], answer: "”Hmix = 0, ”Vmix = 0" } ], assertion: [ { statement1: "Raoult's law is applicable to ideal solutions.", statement2: "For ideal solutions, ”Hmix = 0 and ”Vmix = 0.", options: ["Both true", "Both false", "Only statement 1 is true", "Only statement 2 is true"], answer: "Both true" }, { statement1: "Osmotic pressure is a colligative property.", statement2: "Osmotic pressure depends on the molar mass of the solute.", options: ["Both true", "Both false", "Only statement 1 is true", "Only statement 2 is true"], answer: "Only statement 1 is true" } ], twoMark: [ "Define Henry's law and mention its applications.", "What is reverse osmosis? Give one application.", "Differentiate between ideal and non-ideal solutions.", "Calculate the mass percentage of benzene if 22 g of benzene is dissolved in 122 g of carbon tetrachloride." ], threeMark: [ "Explain the types of deviations from Raoult's law with examples.", "Derive the relationship between relative lowering of vapor pressure and molar mass of solute.", "What are azeotropes? Give examples of minimum and maximum boiling azeotropes." ], fiveMark: [ "Explain the various colligative properties and their importance.", "Discuss the concept of ideal and non-ideal solutions with examples.", "Describe the different types of solutions based on physical states of solute and solvent." ], caseStudy: [ { case: "A solution of two liquids A and B shows positive deviation from Raoult's law. The vapor pressure of pure A is 450 mm Hg and that of pure B is 700 mm Hg. The total vapor pressure of the solution is 800 mm Hg when the mole fraction of A is 0.4.", questions: ["What is the vapor pressure of A in the solution?", "What is the vapor pressure of B in the solution?", "Calculate the mole fraction of B in the vapor phase."] } ] }, // ... (other chapters follow similar pattern with updated content) "Chapter 16": { mcq: [ { question: "Which of the following is not an antibiotic?", options: ["Penicillin", "Sulphanilamide", "Tetracycline", "Chloramphenicol"], answer: "Sulphanilamide" }, { question: "Which type of drug is used for treating allergies?", options: ["Analgesics", "Antihistamines", "Antacids", "Tranquilizers"], answer: "Antihistamines" }, { question: "Which of the following is a natural sweetener?", options: ["Saccharin", "Aspartame", "Sucralose", "Sucrose"], answer: "Sucrose" }, { question: "The drug used as an antiseptic is:", options: ["Chloramphenicol", "Chloroxylenol", "Chloroquine", "Chloramphenicol"], answer: "Chloroxylenol" }, { question: "Which of the following is a cationic detergent?", options: ["Sodium lauryl sulphate", "Sodium stearate", "Cetyltrimethyl ammonium bromide", "Pentaerythritol monostearate"], answer: "Cetyltrimethyl ammonium bromide" } ], assertion: [ { statement1: "Antiseptics can be applied to living tissues.", statement2: "Disinfectants are applied to non-living objects.", options: ["Both true", "Both false", "Only statement 1 is true", "Only statement 2 is true"], answer: "Both true" }, { statement1: "Aspirin is an analgesic.", statement2: "Aspirin is also an antipyretic.", options: ["Both true", "Both false", "Only statement 1 is true", "Only statement 2 is true"], answer: "Both true" } ], twoMark: [ "What are tranquilizers? Give two examples.", "Differentiate between antiseptics and disinfectants.", "What are food preservatives? Give two examples.", "Why is bithional added to soap?" ], threeMark: [ "Explain the classification of drugs on the basis of pharmacological effect.", "What are biodegradable and non-biodegradable detergents? Give examples.", "Describe the cleansing action of soap." ], fiveMark: [ "Explain the classification of drugs with examples.", "Discuss the different types of detergents and their uses.", "Describe the various food additives and their functions." ], caseStudy: [ { case: "A patient was suffering from high fever and body pain. The doctor prescribed a medicine which reduced the fever and also relieved the pain. The medicine also had anti-inflammatory properties.", questions: ["Identify the medicine prescribed.", "What is the chemical name of this medicine?", "What are its other uses?"] } ] } } }; function getRandomQuestions(selectedChapters, type, count) { let allQuestions = []; if (selectedChapters.includes("Full Paper")) { for (let chapter in questions.chemistry) { if (questions.chemistry[chapter][type]) { allQuestions = allQuestions.concat(questions.chemistry[chapter][type]); } } } else { selectedChapters.forEach(chapter => { if (questions.chemistry[chapter] && questions.chemistry[chapter][type]) { allQuestions = allQuestions.concat(questions.chemistry[chapter][type]); } }); } allQuestions = allQuestions.sort(() => Math.random() - 0.5); return allQuestions.slice(0, count); } function showChapterSelection() { document.getElementById('startScreen').classList.add('hidden'); document.getElementById('chapterSelection').classList.remove('hidden'); } function toggleChapters() { const fullPaperCheckbox = document.getElementById('fullPaper'); const checkboxes = document.querySelectorAll('input[name="chapter"]:not(#fullPaper)'); checkboxes.forEach(cb => cb.disabled = fullPaperCheckbox.checked); } function backToStart() { document.getElementById('generatedPaperContainer').classList.add('hidden'); document.getElementById('startContainer').classList.remove('hidden'); document.getElementById('chapterSelection').classList.add('hidden'); document.getElementById('startScreen').classList.remove('hidden'); questionCounter = 1; } function promptSchoolName() { schoolName = prompt("Write your school/institute name").toUpperCase(); if (!schoolName) { alert("School/Institute name is required!"); } else { promptSession(); } } function promptSession() { sessionYear = prompt("Enter the academic session (e.g., 2023-24)").toUpperCase(); if (!sessionYear) { alert("Academic session is required!"); } else { generatePaper(); } } function generatePaper() { document.getElementById('startContainer').classList.add('hidden'); const generatedPaperContainer = document.getElementById('generatedPaperContainer'); generatedPaperContainer.classList.remove('hidden'); generatedPaperContainer.innerHTML = ''; let paperContent = ` <div class="header"> <h2>${schoolName}</h2> </div> <div class="content-area"> <div class="paper-header"> <h3>CHEMISTRY THEORY (043)</h3> <h3>CLASS - XII</h3> <h3>Session: ${sessionYear}</h3> </div> <div class="paper-meta"> <div>Max. Marks: 70</div> <div>Time Allowed: 3 hours</div> </div> <div class="instructions"> <p><strong>General Instructions:</strong></p> <p>Read the following instructions carefully:</p> <ol> <li>There are 33 questions in this question paper with internal choice.</li> <li>SECTION A consists of 16 multiple-choice questions carrying 1 mark each.</li> <li>SECTION B consists of 5 short answer questions carrying 2 marks each.</li> <li>SECTION C consists of 7 short answer questions carrying 3 marks each.</li> <li>SECTION D consists of 2 case-based questions carrying 4 marks each.</li> <li>SECTION E consists of 3 long answer questions carrying 5 marks each.</li> <li>All questions are compulsory.</li> <li>Use of log tables and calculators is not allowed.</li> </ol> </div> `; const selectedChapters = document.getElementById('fullPaper').checked ? ["Full Paper"] : Array.from(document.querySelectorAll('input[name="chapter"]:checked')).map(cb => cb.value); // Section A - MCQs const mcqs = getRandomQuestions(selectedChapters, 'mcq', 16); paperContent += ` <div class="question-section"> <h4 class="section-heading">SECTION A - Multiple Choice Questions (1 mark each)</h4> <p>The following questions are multiple-choice questions with one correct answer. Each question carries 1 mark. There is no internal choice in this section.</p> `; mcqs.forEach((q, i) => { paperContent += ` <div class="question"> <p class="question-text">${questionCounter++}. ${q.question}</p> ${q.options.map((opt, j) => `<p class="option">${String.fromCharCode(65 + j)}. ${opt}</p>` ).join('')} </div> `; }); // Section B - 2 marks const twoMarks = getRandomQuestions(selectedChapters, 'twoMark', 5); paperContent += ` </div> <div class="question-section"> <h4 class="section-heading">SECTION B - Short Answer Questions (2 marks each)</h4> <p>This section contains 5 questions with internal choice in one question. The following questions are very short answer type and carry 2 marks each.</p> `; twoMarks.forEach(q => { paperContent += ` <div class="question"> <p class="question-text">${questionCounter++}. ${q}</p> </div> `; }); // Section C - 3 marks const threeMarks = getRandomQuestions(selectedChapters, 'threeMark', 7); paperContent += ` </div> <div class="question-section"> <h4 class="section-heading">SECTION C - Short Answer Questions (3 marks each)</h4> <p>This section contains 7 questions with internal choice in one question. The following questions are short answer type and carry 3 marks each.</p> `; threeMarks.forEach(q => { paperContent += ` <div class="question"> <p class="question-text">${questionCounter++}. ${q}</p> </div> `; }); // Section D - Case Studies const caseStudies = getRandomQuestions(selectedChapters, 'caseStudy', 2); paperContent += ` </div> <div class="question-section"> <h4 class="section-heading">SECTION D - Case-Based Questions (4 marks each)</h4> <p>The following questions are case-based questions. Each question has an internal choice and carries 4 (2+1+1) marks each. Read the passage carefully and answer the questions that follow.</p> `; caseStudies.forEach(cs => { paperContent += ` <div class="question"> <p class="question-text">${questionCounter++}. ${cs.case}</p> ${cs.questions.map((subQ, j) => `<p class="option">${j + 1}. ${subQ}</p>` ).join('')} </div> `; }); // Section E - 5 marks const fiveMarks = getRandomQuestions(selectedChapters, 'fiveMark', 3); paperContent += ` </div> <div class="question-section"> <h4 class="section-heading">SECTION E - Long Answer Questions (5 marks each)</h4> <p>The following questions are long answer types and carry 5 marks each. All questions have an internal choice.</p> `; fiveMarks.forEach(q => { paperContent += ` <div class="question"> <p class="question-text">${questionCounter++}. ${q}</p> </div> `; }); // Add buttons below the generated paper paperContent += ` </div> <div class="action-buttons"> <button class="btn btn-primary" onclick="downloadPDF()">Download as PDF</button> <button class="btn btn-success" onclick="window.print()">Print</button> <button class="btn btn-danger" onclick="backToStart()">Back to Start</button> </div> </div> `; generatedPaperContainer.innerHTML = paperContent; } async function downloadPDF() { const element = document.getElementById('generatedPaperContainer'); // Create a temporary div with optimized settings const tempDiv = document.createElement('div'); tempDiv.style.position = 'absolute'; tempDiv.style.left = '-9999px'; tempDiv.style.width = '794px'; // A4 width in pXels (210mm) tempDiv.style.backgroundColor = 'white'; tempDiv.style.padding = '20px'; tempDiv.innerHTML = element.innerHTML; document.body.appendChild(tempDiv); try { const pdf = new jsPDF('p', 'mm', 'a4'); const pageWidth = pdf.internal.pageSize.getWidth() - 25.4; // 0.5" margins const pageHeight = pdf.internal.pageSize.getHeight() - 25.4; // Split content into pages let position = 12.7; // Start with 0.5" top margin let remainingHeight = tempDiv.scrollHeight; let pageNum = 1; while (remainingHeight > 0) { // Capture the current page section const canvas = await html2canvas(tempDiv, { scale: 2, windowHeight: pageHeight * 3.78, // mm to px windowWidth: pageWidth * 3.78, y: position * 3.78, // mm to px height: pageHeight * 3.78, useCORS: true, backgroundColor: '#ffffff', logging: false }); const imgData = canvas.toDataURL('image/jpeg', 0.92); // Add page to PDF if (pageNum > 1) { pdf.addPage('a4', 'portrait'); } pdf.addImage(imgData, 'JPEG', 12.7, 12.7, pageWidth, canvas.height * pageWidth / canvas.width); position += pageHeight; remainingHeight -= pageHeight * 3.78; // px pageNum++; } document.body.removeChild(tempDiv); pdf.save(`${schoolName}_Chemistry_Paper.pdf`); } catch (error) { console.error('PDF generation error:', error); alert('Error generating PDF. Please try again.'); document.body.removeChild(tempDiv); } } </script> </body> </html>