Exporting Grid Data to PDF via SFDATAGRID Control by using Following Commands for All Visible Columns where Page Width of the PDF is as per all columns size is not working properly.
Right Side Width of the Last Column has more margin. If In Grid I have 12 Columns, and generating this report for first time then example after last column it has 2 Inch Margin. After that if you remove some Columns or Hide some columns and then export the data to PDF, the right side margin will change from 2 Inch to 5 Inch to 10 Inch..
It is not showing properly.
Following is Link where posted in forum
Codes received for the same :
double width = 0;
foreach (var columns in sfDataGrid1.Columns)
width += columns.ActualWidth;
PdfDocument document = new PdfDocument();
Graphics g = this.sfDataGrid1.CreateGraphics();
width = (float)width * 72 / g.DpiX;
document.PageSettings.Width = (float)width;
var pdfOptions = new PdfExportingOptions();
pdfOptions.FitAllColumnsInOnePage = false;
pdfOptions.Exporting += pdfOptions_Exporting;
var page = document.Pages.Add();
var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, pdfOptions);
PDFGrid.Draw(page, new PointF());
You are requested to please check it and do the needful.