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

Text Wrap Grid to PDF Export

Hi Team,

I have a grid with allowTextWrap settings set to true, the width for each column is also defined. This grid can be exported to PDF.
However when I export it to PDF, not all of the columns fit into an A4 landscape page. The reason is that there are columns that are quite lengthy and take up a lot of the width.

What I would like is to have a fixed width for these columns and the text inside should wrap. Is there a way to set that?

        //PDF Export Method.
        public void PdfExport(IEnumerable data)
            string gridModel = System.Web.HttpContext.Current.Request.Params["GridModel"];
            GridProperties gridProperty = ConvertGridObject(gridModel);
            PdfExport exp = new PdfExport();
            PdfDocument document = new PdfDocument();
            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.Size = PdfPageSize.A4;

            //Settings for text wrap?

            exp.Export(gridProperty, data, "Export.pdf", false, false, "flat-saffron", false, document, "Grid");

        //Grid Model conversion Method.
        private GridProperties ConvertGridObject(string gridProperty)
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
            GridProperties gridProp = new GridProperties();
            foreach (KeyValuePair<string, object> ds in div)
                var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
                if (property != null)
                    Type type = property.PropertyType;
                    string serialize = serializer.Serialize(ds.Value);
                    object value = serializer.Deserialize(serialize, type);
                    property.SetValue(gridProp, value, null);
            return gridProp;

1 Reply

JK Jayaprakash Kamaraj Syncfusion Team May 13, 2016 09:50 AM UTC

Hi Lory, 

Thank you for contacting Syncfusion support. 

We can fit all the Grid columns in a single page by passing the isAutoFit parameter as false to the export method of the PdfExport Class. By default, the isAutoFit property is true.   
        public void PdfExport() 
           exp.Export(gridProperty, result, "Export.pdf", false, false, "flat-saffron", false, false, document, "Grid", false);//here, the 11th parameter is "isAutoFit" which we have set as false.             


Jayaprakash K. 

Live Chat Icon For mobile
Up arrow icon