a4 paper for printing
This commit is contained in:
@@ -244,28 +244,30 @@ async function generatePDF() {
|
|||||||
|
|
||||||
// Capture the sticker as an image
|
// Capture the sticker as an image
|
||||||
const canvas = await html2canvas(stickerElement, {
|
const canvas = await html2canvas(stickerElement, {
|
||||||
scale: 3,
|
scale: 4,
|
||||||
backgroundColor: '#ffffff',
|
backgroundColor: '#ffffff',
|
||||||
useCORS: true,
|
useCORS: true,
|
||||||
logging: false
|
logging: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create PDF with sticker dimensions
|
// Create PDF with A4 dimensions
|
||||||
const imgData = canvas.toDataURL('image/png');
|
const imgData = canvas.toDataURL('image/png');
|
||||||
|
|
||||||
const pdfWidth = 100; // mm
|
|
||||||
const pdfHeight = (canvas.height / canvas.width) * pdfWidth;
|
|
||||||
|
|
||||||
const pdf = new jsPDF({
|
const pdf = new jsPDF({
|
||||||
orientation: pdfHeight > pdfWidth ? 'portrait' : 'landscape',
|
orientation: 'portrait',
|
||||||
unit: 'mm',
|
unit: 'mm',
|
||||||
format: [pdfWidth + 10, pdfHeight + 10]
|
format: 'a4'
|
||||||
});
|
});
|
||||||
|
|
||||||
const x = 5;
|
// Sticker size on A4 (approximately 55mm wide)
|
||||||
const y = 5;
|
const stickerWidth = 55;
|
||||||
|
const stickerHeight = (canvas.height / canvas.width) * stickerWidth;
|
||||||
|
|
||||||
pdf.addImage(imgData, 'PNG', x, y, pdfWidth, pdfHeight);
|
// Position at top-left with small margin
|
||||||
|
const x = 10;
|
||||||
|
const y = 10;
|
||||||
|
|
||||||
|
pdf.addImage(imgData, 'PNG', x, y, stickerWidth, stickerHeight);
|
||||||
|
|
||||||
// Generate filename
|
// Generate filename
|
||||||
const regNumber = regNumberInput.value || 'sticker';
|
const regNumber = regNumberInput.value || 'sticker';
|
||||||
|
|||||||
Reference in New Issue
Block a user