Skip to content

Commit 83fadda

Browse files
feat(core):Merge pull request #159 from mindfiredigital/dev
release
2 parents 9f943f6 + 646b3a8 commit 83fadda

File tree

3 files changed

+3
-151
lines changed

3 files changed

+3
-151
lines changed

packages/core/dist/PageBuilder.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ export class PageBuilder {
467467
format: 'a4',
468468
orientation: 'portrait',
469469
},
470-
margin: MARGIN_BUFFER_PX / 3.78, // Convert pixel buffer to MM (approx 3.78px/mm at 96DPI)
471470
})
472471
.from(sourceElement)
473472
.save();

packages/core/dist/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46920,7 +46920,6 @@ class Of {
4692046920
allowTaint: !0,
4692146921
},
4692246922
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
46923-
margin: a / 3.78,
4692446923
})
4692546924
.from(f)
4692646925
.save(),

packages/core/src/PageBuilder.ts

Lines changed: 3 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -229,146 +229,6 @@ export class PageBuilder {
229229
}
230230
}
231231

232-
// public setupExportPDFButton() {
233-
// const exportButton = document.getElementById('export-pdf-btn');
234-
// if (exportButton) {
235-
// exportButton.addEventListener('click', async () => {
236-
// showNotification('Generating PDF for download...');
237-
// await new Promise(resolve => setTimeout(resolve, 1500));
238-
239-
// const tempContainer = document.createElement('div');
240-
241-
// try {
242-
// const worker = html2pdf();
243-
// if (!worker) {
244-
// showNotification('html2pdf library not loaded');
245-
// return;
246-
// }
247-
248-
// const htmlGenerator = new HTMLGenerator(new Canvas());
249-
// const contentHTML = htmlGenerator.generateHTML();
250-
// let css = htmlGenerator.generateCSS();
251-
252-
// const canvasElement = document.getElementById('canvas');
253-
// const sidebarElement = document.getElementById('sidebar');
254-
// if (!canvasElement) return;
255-
256-
// const MARGIN_MM = 4;
257-
// let canvasWidth: number;
258-
// if (PageBuilder.initialCanvasWidth === null) {
259-
// const rect = canvasElement.getBoundingClientRect();
260-
// if (sidebarElement) {
261-
// canvasWidth =
262-
// rect.width + sidebarElement?.getBoundingClientRect().width;
263-
// } else {
264-
// canvasWidth = rect.width;
265-
// }
266-
// PageBuilder.initialCanvasWidth = canvasWidth;
267-
// } else {
268-
// canvasWidth = PageBuilder.initialCanvasWidth;
269-
// }
270-
271-
// css = css.replace(/min-height:\s*100vh/gi, 'min-height: auto');
272-
273-
// const pdfContent = `
274-
// <style>
275-
// ${css}
276-
277-
// * { box-sizing: border-box; }
278-
// html, body, #pdf-wrapper {
279-
// margin: 0; padding: 0;
280-
// overflow: visible !important;
281-
// font-family: Arial, sans-serif !important;
282-
// background-color: white !important;
283-
// }
284-
285-
// /* CRITICAL VERTICAL FIX: Ensure auto height for full expansion */
286-
// #pdf-wrapper {
287-
// width: ${canvasWidth}px !important;
288-
// height: auto !important;
289-
// overflow: visible !important;
290-
// transform: none !important;
291-
// }
292-
293-
// #canvas.home {
294-
// width: ${canvasWidth}px !important;
295-
// height: auto !important;
296-
// min-height: auto !important;
297-
// transform: none !important;
298-
299-
// position: relative !important;
300-
// margin: 0 !important;
301-
// padding: 0 !important;
302-
// overflow: visible !important;
303-
// }
304-
305-
// /* Added for clean page breaking */
306-
// table, #pdf-wrapper, #canvas.home {
307-
// page-break-inside: avoid !important;
308-
// }
309-
// </style>
310-
// <div id="pdf-wrapper">
311-
// ${contentHTML}
312-
// </div>
313-
// `;
314-
315-
// tempContainer.innerHTML = pdfContent;
316-
// tempContainer.style.cssText = `
317-
// position: absolute;
318-
// left: -99999px;
319-
// top: 0;
320-
// width: ${canvasWidth}px;
321-
// height: auto;
322-
// overflow: visible;
323-
// background-color: white;
324-
// `;
325-
// document.body.appendChild(tempContainer);
326-
327-
// // Give a solid, but shorter, wait time.
328-
// await new Promise(resolve => setTimeout(resolve, 1500));
329-
330-
// const sourceElement = tempContainer.querySelector('#pdf-wrapper') as HTMLElement;
331-
332-
// if (!sourceElement) {
333-
// throw new Error("PDF source element (#pdf-wrapper) not found.");
334-
// }
335-
336-
// await worker
337-
// .set({
338-
// filename: 'exported_page_download.pdf',
339-
// image: { type: 'png', quality: 1 },
340-
// html2canvas: {
341-
// scale: 3,
342-
// width: canvasWidth,
343-
// useCORS: true,
344-
// logging: false,
345-
// backgroundColor: null,
346-
// letterRendering: true,
347-
// allowTaint: true,
348-
// },
349-
// jsPDF: {
350-
// unit: 'mm',
351-
// format: 'a4',
352-
// orientation: 'portrait',
353-
// },
354-
// margin: MARGIN_MM,
355-
// })
356-
// .from(sourceElement)
357-
// .save();
358-
359-
// showNotification('PDF downloaded successfully!');
360-
361-
// } catch (error) {
362-
// console.error('PDF generation error:', error);
363-
// showNotification('Error generating PDF. Check console for details.');
364-
// } finally {
365-
// if (document.body.contains(tempContainer)) {
366-
// document.body.removeChild(tempContainer);
367-
// }
368-
// }
369-
// });
370-
// }
371-
// }
372232
public setupExportPDFButton() {
373233
const exportButton = document.getElementById('export-pdf-btn');
374234
if (exportButton) {
@@ -393,24 +253,19 @@ export class PageBuilder {
393253
const canvasElement = document.getElementById('canvas');
394254
if (!canvasElement) return;
395255

396-
// 1. GET TRUE CONTENT DIMENSIONS (CRUCIAL FIX)
397-
// Use scroll dimensions to get the full size of the content, even if it's off-screen.
398256
const contentWidth = canvasElement.scrollWidth;
399257
const contentHeight = canvasElement.scrollHeight;
400258

401-
// 2. CALCULATE UNIFIED SHRINK FACTOR
402-
const A4_WIDTH_PX = 794; // A4 width at 96 DPI
403-
const A4_HEIGHT_PX = 1123; // A4 height at 96 DPI
404-
const MARGIN_BUFFER_PX = 40; // Small buffer for margins
259+
const A4_WIDTH_PX = 794;
260+
const A4_HEIGHT_PX = 1123;
261+
const MARGIN_BUFFER_PX = 40;
405262
const QUALITY_SCALE = 3;
406263

407-
// Calculate factor needed to shrink content to fit A4 usable area
408264
const widthScaleFactor =
409265
(A4_WIDTH_PX - MARGIN_BUFFER_PX) / contentWidth;
410266
const heightScaleFactor =
411267
(A4_HEIGHT_PX - MARGIN_BUFFER_PX) / contentHeight;
412268

413-
// Use the smallest factor (width or height) to ensure ALL content fits on one page.
414269
const SHRINK_FACTOR = Math.min(
415270
widthScaleFactor,
416271
heightScaleFactor,
@@ -507,7 +362,6 @@ export class PageBuilder {
507362
format: 'a4',
508363
orientation: 'portrait',
509364
},
510-
margin: MARGIN_BUFFER_PX / 3.78, // Convert pixel buffer to MM (approx 3.78px/mm at 96DPI)
511365
})
512366
.from(sourceElement)
513367
.save();

0 commit comments

Comments
 (0)