We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid export PDF/Print

Hi,

I am facing the columns cut off on printing/PDF challenge. 
Could you recommend what is the better way to define page margin and size when using print and PDF from Grid? 
And if there are more columns or like Email address column need more space, does the print and PDF button function can auto fit in a page or code need to handle each column size? 
Would you have better solution to recommend this type of challenge?

Thank you.
Steve


1 Reply

RU Ragavee U S Syncfusion Team October 26, 2016 10:00 AM UTC

Hi Steve, 

Thanks for your interest in Syncfusion products. 

While exporting, the columns will be shown based on the columns width of the Grid. This is the default behavior of exporting. To overcome this problem, use below workaround. In this workaround, we have divided the document width by number of columns and then we have applied calculated width into all grid columns width. Please refer to the below code example.    

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"falsefalse"flat-saffron",falsefalsedocument"Grid"false);//here, the 11th parameter is "isAutoFit" which we have set as false.              
        }  
   

Regards, 
Ragavee U S. 


Loader.
Live Chat Icon For mobile
Up arrow icon