Hello,
I would like it so when a grid exports to PDF the column adjust its size to content, so text does not wrap. Is this possible? Below is an image of what is happening currently.
Thanks,
Charles
|
toolbarClick(args: ClickEventArgs): void {
case 'PDF Export':
this.grid.pdfExport({ allowHorizontalOverflow: true });// Defines the overflow of columns for the pdf grid
break;
}
} |
Hello this option breaks the columns across multiple pages. I need all the columns to be on one page still. The columns should just not wrap the text.
Thanks,
Charles
Thank you for the update. I look forward to more information on Jan. 31st
Thanks,
Charles
|
toolbarClick(args: ClickEventArgs): void { //toolbar click event
if (args.item.text === 'PDF Export') {
let pdfDocument = new PdfDocument();
let page = pdfDocument.pages.add();
let contentFont = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
var grid = (document.getElementById('Grid') as any).ej2_instances[0];
// create a PdfGrid
var pdfGrid = new PdfGrid();
pdfGrid.style.allowHorizontalOverflow = false;
let format = new PdfLayoutFormat();
format.paginateBounds = new RectangleF(
new 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 PointF(0, 0), format);
pdfDocument.save('output.pdf');
pdfDocument.destroy();
}
}
|
Hi,
The proposed solution does not work with stacked headers as it only uses the top level of headers.
Thanks,
Charles
Also the text still wraps. I want all the columns to be on one page but also no text wrapping for the columns.
|
toolbarClick(args: any): void { //toolbar click event
if (args.item.text === 'PDF Export') {
// create a new PDF document
let pdfDocument = new PdfDocument();
// add a page
let page = pdfDocument.pages.add();
// set the font
let font = new PdfStandardFont(2, 10);
// create black brush
let brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
var totalGrid = document.getElementsByClassName('e-grid');
for (var g = 0; g < totalGrid.length; g++) {
var gridI = (totalGrid[g] as any).ej2_instances[0];
// create a PdfGrid
let pdfGrid = new PdfGrid();
pdfGrid.style.allowHorizontalOverflow = false;
// add columns
var columns = gridI.getColumns();
pdfGrid.columns.add(columns.length);
// add headers
var headers = gridI.columns;
var secondLevelHeader = [];
var firstLevelHeader = [];
for (var s = 0; s < headers.length; s++) {
firstLevelHeader.push(headers[s].headerText)
if (headers[s].columns) {
var stackedHeader = true; // enable the stackedHeader flag variable if the grid have stacked header.
for (var k = 0; k < headers[s].columns.length; k++) {
secondLevelHeader.push(headers[s].columns[k].headerText)
}
}
}
if (stackedHeader) {
pdfGrid.headers.add(2);
} else {
pdfGrid.headers.add(1);
}
var secondLevelHeaderOrder = [];
for (var h = 0; h < (pdfGrid.headers as any).rows.length; h++) {
if (h == 0) {
let pdfGridHeader1 = pdfGrid.headers.getHeader(h);
var firstLevelHeaderOrder = 0;
for (var n = 0; n < firstLevelHeader.length; n++) {
if (headers[n].columns) {
var columnSpanLength = headers[n].columns.length;
let secondLevelHeaderOrderIndex = firstLevelHeaderOrder;
for (var t = 0; t < columnSpanLength; t++) {
secondLevelHeaderOrder.push(secondLevelHeaderOrderIndex + t);
}
pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).value = firstLevelHeader[n];
//Apply column span for first level stacked header
pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).columnSpan = columnSpanLength;
firstLevelHeaderOrder = firstLevelHeaderOrder + columnSpanLength
} else if (stackedHeader) {
pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).value = firstLevelHeader[n];
//Apply row span for first level normal header if grid have stacked header
pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).rowSpan = 2;
firstLevelHeaderOrder = firstLevelHeaderOrder + 1
} else {
pdfGridHeader1.cells.getCell(n).value = firstLevelHeader[n];
}
}
} else {
let pdfGridHeader2 = pdfGrid.headers.getHeader(h);
for (var st = 0; st < secondLevelHeader.length; st++) {
pdfGridHeader2.cells.getCell(secondLevelHeaderOrder[st]).value = secondLevelHeader[st];
}
}
}
stackedHeader = false
// add rows
var data = gridI.dataSource;
for (let i = 0; i < data.length; i++) {
let pdfGridRow = pdfGrid.rows.addRow();
for (let j = 0; j < columns.length; j++) {
var field = columns[j].field;
if (field) {
pdfGridRow.cells.getCell(j).value = data[i][field].toString();
}
}
}
if (g == 0) {
// drawing a grid
var gridResult = pdfGrid.draw(
page,
new PointF(0, 0)
);
} else {
let layoutFormat = new PdfGridLayoutFormat();
layoutFormat.layout = 0; //PdfLayoutType.Paginate;
layoutFormat.break = 0; //PdfLayoutBreakType.FitPage;
// drawing a grid based on PdfGridLayoutResult value
gridResult = pdfGrid.draw(
gridResult.page,
new PointF(0, gridResult.bounds.y + gridResult.bounds.height + 30),
layoutFormat
);
}
}
//Save the document.
pdfDocument.save('MultipleGrid_Result.pdf');
pdfDocument.destroy();
}
} |
By default, while exporting a pdf export the Grid will auto adjust in the pdf layout, to render all columns in single page, the Grid cell will adjust based on pdf cell. So, when the content overflow in the pdf cell it will automatically wrap the text and adjust the content. It was the default behavior.
I understand that by default it will warp the text I do not want it to.
We used another library for pdf exports in the past and it was able to fit all the columns on one page without the columns text wrapping. Below is an example
With Syncfusion the pdf can fit all the columns onto one page but the columns will wrap the text which looks ugly. We do not want this behavior. Below is an example of that.
thanks,
Charles
HI,
Thanks for the update.
Hi,
Attached is all the code I am using for this. As for page size we CAN NOT change that. We CAN however change font size.
Thank you for the update
|
// Grid’s created event handler
created() {
(this.grid.pdfExportModule as any).processSectionExportProperties = function (section, pdfExportProperties) {
var pdfPageSettings = new PdfPageSettings();
var doc = this.pdfDocument;
pdfPageSettings.margins.all = 0;
// The Grid size is retrieved
var gridResult = this.parent.element.getBoundingClientRect();
// The pdf size is calculated from the grid size
// You can customize the below values based on your requirement for modifying the page size
var result = new SizeF(gridResult.width + 300, gridResult.height + 300);
// The calculated size is set as the pdf document size and returned
pdfPageSettings.size = new SizeF(result.width, result.height);
section.setPageSettings(pdfPageSettings);
return section;
}
} |
Hi,
Thank you so much this has fixed all my problems!
Hi,
After some more testing this does work well for displaying the pdf correctly however if you go to print the pdf out it cuts off some of the columns. Below is an image of what happens.
Hi,
Unfortunately this is not an option as we can not rely on our customers doing this every time they need to print some
Hi,
Thank you for the update I appreciate all the work that has been put into this item.
Hi,
As discussed above this does not fix our problems as text will still wrap. This does fix it, but when printing it cuts columns off.