Skip to content

Commit 13d7553

Browse files
committed
Directly download .PNG and .SVG files when clicking on Export Button with Preview in new Tab.
1 parent a3dca32 commit 13d7553

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

projects/angular-editor-fabric-js/src/lib/angular-editor-fabric-js.component.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,36 @@ export class FabricjsEditorComponent implements AfterViewInit {
559559
image.src = this.canvas.toDataURL({format: 'png'});
560560
const w = window.open('');
561561
w.document.write(image.outerHTML);
562+
this.downLoadImage();
563+
}
564+
565+
downLoadImage(){
566+
const c = this.canvas.toDataURL({format: 'png'});
567+
const downloadLink = document.createElement('a');
568+
document.body.appendChild(downloadLink);
569+
downloadLink.href = c;
570+
downloadLink.target = '_self';
571+
downloadLink.download = Date.now()+'.png';
572+
downloadLink.click();
562573
}
563574

564575
rasterizeSVG() {
565576
const w = window.open('');
566577
w.document.write(this.canvas.toSVG());
578+
this.downLoadSVG();
567579
return 'data:image/svg+xml;utf8,' + encodeURIComponent(this.canvas.toSVG());
568580
}
569581

582+
downLoadSVG(){
583+
const c = 'data:image/svg+xml;utf8,' + encodeURIComponent(this.canvas.toSVG());
584+
const downloadLink = document.createElement('a');
585+
document.body.appendChild(downloadLink);
586+
downloadLink.href = c;
587+
downloadLink.target = '_self';
588+
downloadLink.download = Date.now()+'.svg';
589+
downloadLink.click();
590+
}
591+
570592
saveCanvasToJSON() {
571593
const json = JSON.stringify(this.canvas);
572594
localStorage.setItem('Kanvas', json);

0 commit comments

Comments
 (0)