Skip to content

Commit ed6d513

Browse files
authored
Merge pull request #124 from AOSSIE-Org/revert-114-fix/naman
Revert "Fix : PDF Generation Issues"
2 parents b17c11d + 678d490 commit ed6d513

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

eduaid_web/src/pages/Output.jsx

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ const Output = () => {
5858
});
5959
}
6060

61-
if (questionType === "get_mcq") {
61+
if (questionType === "get_mcq") {
6262
qaPairsFromStorage["output"].forEach((qaPair) => {
63-
const options = qaPair.options;
64-
const correctAnswer = qaPair.answer;
63+
const options = qaPair.answer
64+
.filter((ans) => !ans.correct)
65+
.map((ans) => ans.answer);
66+
const correctAnswer = qaPair.answer.find(
67+
(ans) => ans.correct
68+
)?.answer;
6569

6670
combinedQaPairs.push({
67-
question: qaPair.question_statement,
71+
question: qaPair.question,
6872
question_type: "MCQ_Hard",
6973
options: options,
7074
answer: correctAnswer,
@@ -127,40 +131,18 @@ const Output = () => {
127131
let y = 700; // Starting y position for content
128132
let questionIndex = 1;
129133

130-
console.log("here inside downloading", qaPairs)
131-
132134
qaPairs.forEach((qaPair) => {
133135
if (y < 50) {
134136
page = pdfDoc.addPage();
135137
y = 700;
136138
}
137139

138-
// i'm implementing a question text wrapping logic so that it doesn't overflow the page
139-
const questionText = `Q${questionIndex}) ${qaPair.question}`;
140-
const maxLineLength = 67;
141-
const lines = [];
142-
143-
let start = 0;
144-
while (start < questionText.length) {
145-
let end = start + maxLineLength;
146-
if (end < questionText.length && questionText[end] !== ' ') {
147-
while (end > start && questionText[end] !== ' ') {
148-
end--;
149-
}
150-
}
151-
if (end === start) {
152-
end = start + maxLineLength;
153-
}
154-
lines.push(questionText.substring(start, end).trim());
155-
start = end + 1;
156-
}
157-
158-
lines.forEach((line) => {
159-
page.drawText(line, { x: 50, y, size: 15 });
160-
y -= 20;
140+
page.drawText(`Q${questionIndex}) ${qaPair.question}`, {
141+
x: 50,
142+
y,
143+
size: 15,
161144
});
162-
163-
y -= 10;
145+
y -= 30;
164146

165147
if (qaPair.question_type === "Boolean") {
166148
// Create radio buttons for True/False
@@ -208,11 +190,6 @@ const Output = () => {
208190
};
209191
drawRadioButton(option, false);
210192
});
211-
212-
if (questionIndex % 5 === 0) {
213-
page = pdfDoc.addPage();
214-
y = 700;
215-
}
216193
} else if (qaPair.question_type === "Short") {
217194
// Text field for Short answer
218195
const answerField = form.createTextField(

0 commit comments

Comments
 (0)