when exporting to pdf:
Thanks
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" allowPdfExport="true" toolbarClick="toolbarClick" toolbar="@(new List<string>() {"PdfExport"})" allowPaging="true">
---------
</ejs-grid>
<script >
function toolbarClick(args) {
//Create a new PDF document
let pdfDocument = new ej.pdfexport.PdfDocument();
let page = pdfDocument.pages.add();
//Header image.
let headerImage = new ej.pdfexport.PdfBitmap(GetImage());
//Draw the iamge.
page.graphics.drawImage(headerImage, 10, 0, 200, 100);
let titleFont = new ej.pdfexport.PdfStandardFont(
ej.pdfexport.PdfFontFamily.Helvetica,
20
);
let contentFont = new ej.pdfexport.PdfStandardFont(
ej.pdfexport.PdfFontFamily.Helvetica,
10
);
let brush = new ej.pdfexport.PdfSolidBrush(new ej.pdfexport.PdfColor(100, 100, 100));
//header content
page.graphics.drawString(
"Mountain-200",
titleFont,
null,
brush,
220,
0,
page.getClientSize().width - 220,
100,
null
);
page.graphics.drawString(
"Product No: BK-M68B-38",
contentFont,
null,
brush,
220,
25,
page.getClientSize().width - 220,
100,
null
);
page.graphics.drawString(
"Size: 38",
contentFont,
null,
brush,
220,
40,
page.getClientSize().width - 220,
100,
null
);
page.graphics.drawString(
"Weight: 25",
contentFont,
null,
brush,
220,
55,
page.getClientSize().width - 220,
100,
null
);
page.graphics.drawString(
"Price: $2,294.99",
contentFont,
null,
brush,
220,
70,
page.getClientSize().width - 220,
100,
null
);
var grid = document.getElementById('Grid').ej2_instances[0];
// create a PdfGrid
var pdfGrid = new ej.pdfexport.PdfGrid();
pdfGrid.style.allowHorizontalOverflow = false;
let format = new ej.pdfexport.PdfLayoutFormat();
format.paginateBounds = new ej.pdfexport.RectangleF(
new ej.pdfexport.PointF(0, 0),
page.getClientSize()
);
var collength = grid.columns.length;
pdfGrid.columns.add(collength);
// add header
pdfGrid.headers.add(1);
var pdfGridHeader = pdfGrid.headers.getHeader(0);
for (let j = 0; j < collength; j++) {
pdfGridHeader.cells.getCell(j).value = grid.columns[j].headerText;
}
let pdfGridRow1 = [];
// add rows
for (let k = 0; k < grid.dataSource.length; k++) {
pdfGridRow1[k] = pdfGrid.rows.addRow();
}
for (let k = 0; k < grid.dataSource.length; k++) {
for (let r = 0; r < grid.columnModel.length; r++) {
pdfGridRow1[k].cells.getCell(r).value = grid.dataSource[k][grid.columnModel[r].field].toString();
}
}
// draw the PdfGrid
pdfGrid.draw(page, new ej.pdfexport.PointF(10, 120), format);
pdfDocument.save('output.pdf');
pdfDocument.destroy();
}
function GetImage() {
-------
}
</script> |