fix download

This commit is contained in:
amazuecos
2025-03-25 18:29:39 +01:00
parent 7b3096efb3
commit 8caa6e8bab
4 changed files with 64 additions and 23 deletions

View File

@ -614,21 +614,24 @@ class PresupuestoAdminEdit {
const svgData = serializer.serializeToString(shapeSvgEl);
const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
const svgUrl = URL.createObjectURL(svgBlob);
const img = new Image();
const img = new Image(shapeSvgEl.getBoundingClientRect().width,shapeSvgEl.getBoundingClientRect().height);
img.onload = () => {
const scaleFactor = 3; // Increase resolution (e.g., 2x, 3x)
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
// Scale canvas for high resolution
const width = img.naturalWidth || img.width;
const height = img.naturalHeight || img.height;
canvas.width = width * scaleFactor;
canvas.height = height * scaleFactor;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
ctx.scale(scaleFactor, scaleFactor);
ctx.drawImage(img, 0,0,width,height);
const pngUrl = canvas.toDataURL('image/png');
const downloadLink = document.createElement('a');
downloadLink.href = pngUrl;
downloadLink.download = filename ?? '.png';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
URL.revokeObjectURL(svgUrl);
};