normalguy5 commited on
Commit
d214577
·
verified ·
1 Parent(s): 6e4629a

make it so that the pdf it downloads is more refined and take as less page as possible

Browse files
Files changed (1) hide show
  1. script.js +42 -22
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
- // Compact styling
117
- doc.setFont('courier', 'normal');
118
- doc.setFontSize(8);
119
- doc.setTextColor(30);
120
 
121
  const points = Array.from(keyPointsContainer.querySelectorAll('p')).map(p => p.textContent);
122
- const margin = 10;
123
- const colWidth = 55;
124
- const lineHeight = 4.5;
125
- let y = 15;
 
126
 
127
- // Create 3 columns for maximum density
128
  for (let i = 0; i < points.length; i++) {
129
- const col = i % 3;
130
- const xPos = margin + (col * 60);
131
 
132
- // Add new page if needed
133
- if (y > 270) {
134
- doc.addPage();
135
- y = 15;
136
  }
137
 
138
- // Split text to fit column width
139
- const lines = doc.splitTextToSize(points[i], colWidth);
140
- doc.text(lines, xPos, y);
 
 
 
 
 
 
 
 
141
 
142
  // Update y position for next item
143
- y += (lines.length * lineHeight) + 2;
144
  }
145
- doc.save('cheat-sheet.pdf');
146
- } catch (error) {
 
 
 
 
 
 
 
 
 
 
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
  }