make it so that the pdf it downloads is more refined and take as less page as possible
Browse files
script.js
CHANGED
|
@@ -110,40 +110,60 @@ pointElement.addEventListener('click', () => {
|
|
| 110 |
const doc = new jsPDF({
|
| 111 |
orientation: 'portrait',
|
| 112 |
unit: 'mm',
|
| 113 |
-
format: 'a4'
|
|
|
|
| 114 |
});
|
| 115 |
|
| 116 |
-
//
|
| 117 |
-
doc.setFont('
|
| 118 |
-
doc.setFontSize(
|
| 119 |
-
doc.setTextColor(
|
| 120 |
|
| 121 |
const points = Array.from(keyPointsContainer.querySelectorAll('p')).map(p => p.textContent);
|
| 122 |
-
const margin =
|
| 123 |
-
const
|
| 124 |
-
const
|
| 125 |
-
|
|
|
|
| 126 |
|
| 127 |
-
// Create
|
| 128 |
for (let i = 0; i < points.length; i++) {
|
| 129 |
-
const col = i %
|
| 130 |
-
const xPos = margin + (col *
|
| 131 |
|
| 132 |
-
// Add new page if needed
|
| 133 |
-
if (y >
|
| 134 |
-
doc.addPage();
|
| 135 |
-
y =
|
| 136 |
}
|
| 137 |
|
| 138 |
-
//
|
| 139 |
-
const lines = doc.splitTextToSize(points[i], colWidth);
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
// Update y position for next item
|
| 143 |
-
y += (lines.length * lineHeight)
|
| 144 |
}
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
console.error('PDF Export Error:', error);
|
| 148 |
alert('Failed to generate PDF. Please try again.');
|
| 149 |
}
|
|
|
|
| 110 |
const doc = new jsPDF({
|
| 111 |
orientation: 'portrait',
|
| 112 |
unit: 'mm',
|
| 113 |
+
format: 'a4',
|
| 114 |
+
compress: true
|
| 115 |
});
|
| 116 |
|
| 117 |
+
// Ultra-compact styling
|
| 118 |
+
doc.setFont('Helvetica', 'normal');
|
| 119 |
+
doc.setFontSize(6);
|
| 120 |
+
doc.setTextColor(20);
|
| 121 |
|
| 122 |
const points = Array.from(keyPointsContainer.querySelectorAll('p')).map(p => p.textContent);
|
| 123 |
+
const margin = 5;
|
| 124 |
+
const pageWidth = doc.internal.pageSize.width - (margin * 2);
|
| 125 |
+
const colWidth = pageWidth / 4 - 2; // 4 columns with small gap
|
| 126 |
+
const lineHeight = 3;
|
| 127 |
+
let y = margin;
|
| 128 |
|
| 129 |
+
// Create 4 columns for maximum density
|
| 130 |
for (let i = 0; i < points.length; i++) {
|
| 131 |
+
const col = i % 4;
|
| 132 |
+
const xPos = margin + (col * (colWidth + 2));
|
| 133 |
|
| 134 |
+
// Add new page if needed with tighter margins
|
| 135 |
+
if (y > doc.internal.pageSize.height - margin) {
|
| 136 |
+
doc.addPage('a4', 'portrait');
|
| 137 |
+
y = margin;
|
| 138 |
}
|
| 139 |
|
| 140 |
+
// Optimize text splitting
|
| 141 |
+
const lines = doc.splitTextToSize(points[i].replace(/\s+/g, ' '), colWidth);
|
| 142 |
+
|
| 143 |
+
// Skip empty lines
|
| 144 |
+
if (lines.length === 0) continue;
|
| 145 |
+
|
| 146 |
+
// Add text with minimal spacing
|
| 147 |
+
doc.text(lines, xPos, y, {
|
| 148 |
+
maxWidth: colWidth,
|
| 149 |
+
lineHeightFactor: 0.9
|
| 150 |
+
});
|
| 151 |
|
| 152 |
// Update y position for next item
|
| 153 |
+
y += (lines.length * lineHeight);
|
| 154 |
}
|
| 155 |
+
|
| 156 |
+
// Compact PDF output
|
| 157 |
+
doc.setProperties({
|
| 158 |
+
title: 'Compact Cheat Sheet',
|
| 159 |
+
subject: 'Exam Cheat Sheet',
|
| 160 |
+
creator: 'PDF Nugget Miner'
|
| 161 |
+
});
|
| 162 |
+
// Save with optimized name and compression
|
| 163 |
+
doc.save(`cheat-sheet-${new Date().toISOString().slice(0,10)}.pdf`, {
|
| 164 |
+
compression: true
|
| 165 |
+
});
|
| 166 |
+
} catch (error) {
|
| 167 |
console.error('PDF Export Error:', error);
|
| 168 |
alert('Failed to generate PDF. Please try again.');
|
| 169 |
}
|