public void ExportToPdf(string GridModel)
{
PdfExport exp = new PdfExport();
var DataSource = newNorthwindDataContext().OrdersViews.Take(50).ToList();
GridProperties obj = ConvertGridObject(GridModel);
PdfDocument document = new PdfDocument();
var marginWidth = document.PageSettings.Margins; // here we will get page margin sizes
var size = ((Math.Round(document.PageSettings.Size.Width)) - (marginWidth.Top + marginWidth.Bottom + marginWidth.Left + marginWidth.Right)); // here we will get document size without margin margin size
var width = Math.Round(size / obj.Columns.Count);
for (int i = 0; i < obj.Columns.Count; i++)
{
obj.Columns[i].Width = width; // here we have applied calculated width for all columns.
}
exp.Export(obj, DataSource, "Export.pdf", false, false, "flat-saffron",false, false, document, "Grid", false);//here, the 11th parameter is "isAutoFit" which we have set as false.
} |