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.
Unfortunately, activation email could not send to your email. Please try again.

Grid export PDF/Print

Thread ID:

Created:

Updated:

Platform:

Replies:

127095 Oct 25,2016 06:37 PM Oct 26,2016 06:00 AM ASP.NET MVC 1
loading
Tags: Grid
Steve Lei
Asked On October 25, 2016 06:37 PM

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


Ragavee U S [Syncfusion]
Replied On October 26, 2016 06:00 AM

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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;