Dear Sir,
Following Code is not working..
Unable to getcurrentPercentGridPDFConverter pdfConvertor = new GridPDFConverter(); //Range of rows to be exported in a PDF file pdfConvertor.ExportRange = 40; //Merged Export. pdfConvertor.ExportToPdfWithMerge(ref doc, this.gridGroupingControl1.TableControl ); //Resize the column to fit in PDF. float tempPercent = currentPercent; this.gridGroupingControl1.BeginUpdate(); PdfDocument doc = new PdfDocument(); Hashtable ht = new Hashtable(); for (int i = 0; i < gridGroupingControl1.TableDescriptor.Columns.Count; i++) ht.Add(i, gridGroupingControl1.TableDescriptor.Columns[i].Width) float gridWidth = this.gridGroupingControl1.TableModel.ColWidths.GetTotal(0, gridGroupingControl1.TableDescriptor.Columns.Count); if (gridWidth > doc.PageSettings.Width + 80) { float scale = (gridWidth / (doc.PageSettings.Width + 80)) - currentPercent; zoomGrid(currentPercent - scale); }
Please send me sample file for the same
|
GridPDFConverter pdfConvertor = new GridPDFConverter();
PdfDocument doc = new PdfDocument();
//Range of rows to be exported in a PDF file
pdfConvertor.ExportRange = 40;
//Merged Export.
pdfConvertor.Exporting += PdfConvertor_Exporting;
pdfConvertor.ExportToPdfWithMerge(ref doc, this.gridGroupingControl1.TableControl);
//Reset the zoomGrid
zoom.zoomGrid(currentPercent.ToString());
private void PdfConvertor_Exporting(object sender, PDFExportingEventArgs e)
{
this.gridGroupingControl1.BeginUpdate();
PdfDocument doc = e.PdfDocument;
Hashtable ht = new Hashtable();
for (int i = 0; i < gridGroupingControl1.TableDescriptor.Columns.Count; i++)
ht.Add(i, gridGroupingControl1.TableDescriptor.Columns[i].Width);
float gridWidth = this.gridGroupingControl1.TableModel.ColWidths.GetTotal(0, gridGroupingControl1.TableDescriptor.Columns.Count);
if (gridWidth > doc.PageSettings.Width + 80)
{
float scale = (gridWidth / (doc.PageSettings.Width+80));
zoomGrid(currentPercent - scale);
}
}
private void zoomGrid(float percent)
{
ZoomGroupingGrid zoom = new ZoomGroupingGrid(this.gridGroupingControl1);
zoom.zoomGrid(percent.ToString());
} |
|
void pdfConvertor_Exporting(object sender, PDFExportingEventArgs e)
{
//You can use any of the followings
e.PdfDocument.PageSettings.Width = this.gridGroupingControl1.TableModel.ColWidths.GetTotal(0,this.gridGroupingControl1.TableModel.ColCount);
e.PdfDocument.PageSettings.Orientation = Syncfusion.Pdf.PdfPageOrientation.Landscape;
}
|
|
Query |
Solution | |
|
while exporting grid to pdf in A4 size either in Landscape or Portrait,
the width should be fix & same size and all columns of the grid should appear within page . |
To fit all the columns exactly in a page, you could manually calculate the column width based on the PdfDocument page width then you can assign that calculate width using PrintingMode property in QueryColWidth event. Please refer to the below code example and the sample,
Code example
| |
|
while exporting grid to pdf, the selected row color and the other row color should be same. |
To avoid the selection color while printing the grid to pdf, you could handle the PrepareViewStyleInfo event. Please refer to the below code example,
Code example
this.gridGroupingControl1.TableControl.PrepareViewStyleInfo += GridGroupingControl1_TableControlPrepareViewStyleInfo;
private void GridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (this.gridGroupingControl1.TableControl.PrintingMode)
{
GridTableCellStyleInfo style = e.Style as GridTableCellStyleInfo;
if (style != null && style.TableCellIdentity.DisplayElement.Kind == Syncfusion.Grouping.DisplayElementKind.Record && style.TableCellIdentity.DisplayElement.GetRecord().IsSelected()
&& (style.TableCellIdentity.TableCellType != GridTableCellType.RecordRowHeaderCell && style.TableCellIdentity.TableCellType != GridTableCellType.AlternateRecordRowHeaderCell))
{
e.Cancel = true;
}
}
} |