|
<script id="template-codigo-barras" type="text/x-template">
<div class="barcode-elem">Barcode</div>
</script>
<script>
// Grid’s dataBound event function
function dataBound(args) {
// Get all the div elements rendered inside the cell using column template
var barCodeElements = this.element.querySelectorAll('.barcode-elem');
var i = 0;
while (i < barCodeElements.length) {
// Initialize barcode generator
var barcode = new ej.barcodegenerator.BarcodeGenerator({
width: '100px',
height: '100px',
mode: 'SVG',
type: 'Ean13',
value: '123123123124',
});
// Append the initialized barcode to the div element
barcode.appendTo(barCodeElements[i]);
i++;
}
}
</script> |
|
// Grid’s beforePrint event function
function beforePrint(args) {
var barCodeElements = args.element.querySelectorAll('.barcode-elem');
var i = 0;
while (i < barCodeElements.length) {
var barcode = new ej.barcodegenerator.BarcodeGenerator({
width: '200px',
height: '150px',
mode: 'SVG',
type: 'Ean13',
value: '123123123124',
});
barcode.appendTo(barCodeElements[i]);
i++;
}
} |
|
// Barcode component is initialized
var barcode = new ej.barcodegenerator.BarcodeGenerator({
width: '200px',
height: '150px',
mode: 'SVG',
type: 'Ean13',
value: '123123123124',
});
var image = [];
var imgStrings = [];
// Grid's toolbarClick event
function toolbarClick(args) {
var gridObj = document.getElementById("Grid").ej2_instances[0];
if (args.item.id === 'Grid_pdfexport') {
var barcodeInst = barcode;
// Executed for each data
for (var i = 0; i < gridObj.dataSource.length; i++) {
// blob url is created for the barcode component
var url = window.URL.createObjectURL(new Blob([(new XMLSerializer()).serializeToString(barcodeInst.barcodeCanvas)], { type: 'image/svg+xml' }));
image.push(new Image());
// Triggered on image load
image[i].onload = (e) => {
// A blank canvas is created with the required properties
var element = document.createElement("canvas");
element.setAttribute("id", "ej2-canvas" + i);
element.setAttribute("width", "150");
element.setAttribute("height", "150");
// The target image is drawn in the drawing context of the canvas
var ctx = element.getContext('2d');
ctx.drawImage(e.currentTarget, 0, 0);
// The context is converted to image string and pushed into a global variable
var imageString = element.toDataURL('image/jpeg').replace('image/jpeg', 'image/octet-stream');
imageString = imageString.slice(imageString.indexOf(',') + 1);
imgStrings.push(imageString);
// Pdf is exported when all the image are convreted
imgStrings.length == gridObj.dataSource.length && gridObj.pdfExport();
}
image[i].src = url;
}
}
}
// Grid's pdfQueryCellInfo event
function pdfQueryCellInfo(args) {
if (args.column.headerText == 'CodigoBarras') {
// The image string is mapped as bitmap and assigned to the cell value
args.value = new ej.pdfexport.PdfBitmap(imgStrings[args.cell.row.rowIndex]);
}
} |
Hi Diego,
Thanks for the update. Please get back to us if you face any issues or require any further assistance.
Regards,Sujith R
Hi Diego,
We are not able to properly understand the requirement from your query. Is your requirement to print or generate a pdf in a page directly in the browser without invoking the Grid’s print/pdf export method or cancel the print/pdf export that is called from the Grid. Please provide more details on the this so that we can further validate it from our end and provide you the response.
Let us know if you have any concerns.Regards,Sujith R