Skip to content

Commit

Permalink
Merge pull request #124 from AOSSIE-Org/revert-114-fix/naman
Browse files Browse the repository at this point in the history
Revert "Fix : PDF Generation Issues"
  • Loading branch information
Aditya062003 authored Jan 9, 2025
2 parents b17c11d + 678d490 commit ed6d513
Showing 1 changed file with 13 additions and 36 deletions.
49 changes: 13 additions & 36 deletions eduaid_web/src/pages/Output.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ const Output = () => {
});
}

if (questionType === "get_mcq") {
if (questionType === "get_mcq") {
qaPairsFromStorage["output"].forEach((qaPair) => {
const options = qaPair.options;
const correctAnswer = qaPair.answer;
const options = qaPair.answer
.filter((ans) => !ans.correct)
.map((ans) => ans.answer);
const correctAnswer = qaPair.answer.find(
(ans) => ans.correct
)?.answer;

combinedQaPairs.push({
question: qaPair.question_statement,
question: qaPair.question,
question_type: "MCQ_Hard",
options: options,
answer: correctAnswer,
Expand Down Expand Up @@ -127,40 +131,18 @@ const Output = () => {
let y = 700; // Starting y position for content
let questionIndex = 1;

console.log("here inside downloading", qaPairs)

qaPairs.forEach((qaPair) => {
if (y < 50) {
page = pdfDoc.addPage();
y = 700;
}

// i'm implementing a question text wrapping logic so that it doesn't overflow the page
const questionText = `Q${questionIndex}) ${qaPair.question}`;
const maxLineLength = 67;
const lines = [];

let start = 0;
while (start < questionText.length) {
let end = start + maxLineLength;
if (end < questionText.length && questionText[end] !== ' ') {
while (end > start && questionText[end] !== ' ') {
end--;
}
}
if (end === start) {
end = start + maxLineLength;
}
lines.push(questionText.substring(start, end).trim());
start = end + 1;
}

lines.forEach((line) => {
page.drawText(line, { x: 50, y, size: 15 });
y -= 20;
page.drawText(`Q${questionIndex}) ${qaPair.question}`, {
x: 50,
y,
size: 15,
});

y -= 10;
y -= 30;

if (qaPair.question_type === "Boolean") {
// Create radio buttons for True/False
Expand Down Expand Up @@ -208,11 +190,6 @@ const Output = () => {
};
drawRadioButton(option, false);
});

if (questionIndex % 5 === 0) {
page = pdfDoc.addPage();
y = 700;
}
} else if (qaPair.question_type === "Short") {
// Text field for Short answer
const answerField = form.createTextField(
Expand Down

0 comments on commit ed6d513

Please sign in to comment.