I'm trying to print the content of a% HTML% tag, so everything goes perfectly, so what I'm doing through the div
library is that you can write a text and add an image as shown below:
But, when trying to print the content of fabricJS
, which ranges from the hello world to the section of div
I have found that the content of the canvas does not print it and shows it in white:
HTML CODE
<div class="card mb-3 shadow p-3 mb-5 bg-white rounded">
<div class="container" id="print-section">
¡Hola Mundo!
<canvas id="myCanvas" width="400px" height="100px" style="border:solid;">
Hola Mundo!
</canvas>
</div>
<hr>
<div class="form-row">
<div class="col-md-6">
<button class="btn btn-primary btn-block" (click)="print('printSectionId')">Print</button>
</div>
<div class="col-md-6">
<button class="btn btn-success btn-block" (click)="inciarCanvas()">Etiqueta</button>
</div>
</div>
</div>
TYPESCRIPT / ANGULAR CODE
canvas: any;
constructor() { }
print(): void {
let printContents,
popupWin;
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
popupWin.document.open();
popupWin.document.write('
<html>
<head>
<title>Print tab</title>
<style>
</style>
</head>
<body onload="window.print();window.close()">${printContents}</body>
</html>'
);
popupWin.document.close();
}
ngOnInit() {
this.canvas = new fabric.Canvas('myCanvas', );
this.canvas.add(new fabric.IText('¡Escribe lo que tu quieras!'));
fabric.Image.fromURL('https://assets-cdn.github.com/images/icons/emoji/unicode/1f47d.png', (image) => {
image.set({
left: 50,
top: 70,
});
this.canvas.add(image);
});
}
Note: If I press the
canvas
+ctrl
keys, the entire content of the page, including the canvas, is shown and loaded in the canvas.
What can I do to solve this, or what suggestions can you give me to get what I want?
Beforehand, thank you very much!