This is a migrated thread and some comments may be shown as answers.

[Solved] ExportToPdf and NoWrap

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 27 Aug 2009, 03:45 PM
I am trying to make my columns not wrap in the resultant PDF document but have had no luck. Any help is appreciated. Here is my code:

        protected void ButtonExportToPDF_Click(object sender, EventArgs e)
        {
            isPdfExport = true;

            ConfigureExport();
            RadGridFacility.ExportSettings.Pdf.PaperSize = GridPaperSize.Legal;
            RadGridFacility.ExportSettings.Pdf.PageWidth = Unit.Parse("356mm");
            RadGridFacility.ExportSettings.Pdf.PageHeight = Unit.Parse("216mm");

            RadGridFacility.MasterTableView.Rebind();
            RadGridFacility.MasterTableView.ExportToPdf();
        }

 

        protected void RadGridFacility_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (isPdfExport && (e.Item is GridHeaderItem || e.Item is GridDataItem))
            {
                if (e.Item is GridDataItem)
             {
                    GridDataItem dataItem = (GridDataItem)e.Item;
                    dataItem.Style["font-size"] = "7pt";
                    dataItem.Style["white-space"] = "nowrap";

                    foreach (TableCell cell in dataItem.Cells)
                    {
                        cell.Style["white-space"] = "nowrap";
                        cell.Style["color"] = "red";
                    }
                }
                else
             {
                    GridHeaderItem headerItem = (GridHeaderItem)e.Item;
                    headerItem.Style["font-size"] = "7pt";
                    headerItem.Style["font-weight"] = "bold";
                }
            }
        }

        public void ConfigureExport()
        {
            RadGridFacility.ExportSettings.ExportOnlyData = true;
            RadGridFacility.ExportSettings.IgnorePaging = CheckBoxIgnorePaging.Checked;
            RadGridFacility.ExportSettings.OpenInNewWindow = false;
        }

Also tried code below but all columns are of type GridExpandColumn even tho they are GridBoundColumns in the aspx?? GridExpandColumn does not have the DataFormatString property

protected void RadGridFacility_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
       //add more column types to the conditional check if needed
       if (e.Column is GridBoundColumn)
       {
           (e.Column as GridBoundColumn).DataFormatString = "<nobr>{0}</nobr>";
       }
}

                        <telerik:RadGrid ID="RadGridFacility" runat="server" AllowPaging="True"
                            PageSize="100" AllowSorting="True"
                                AutoGenerateColumns="False" DataKeyNames="FacilityID"
                                DataSourceID="EntityDataSourceFacility" GridLines="None" Skin="Vista"
                                onitemdatabound="RadGridFacility_ItemDataBound"
                                 Font-Size="XX-Small"
                            onitemcreated="RadGridFacility_ItemCreated"
                            oncolumncreated="RadGridFacility_ColumnCreated" >

                            <PagerStyle Mode="NextPrevNumericAndAdvanced" PageButtonCount="5"
                                PagerTextFormat="Change page: {4} &amp;nbsp;Displaying page {0} of {1}. Total items: {5}." AlwaysVisible="True" />
                            <headercontextmenu><collapseanimation
                            duration="200" type="OutQuint" /></headercontextmenu>
                           
                            <mastertableview datakeynames="FacilityID"
                                datasourceid="EntityDataSourceFacility">
                                <norecordstemplate><div>There are no records to display</div></norecordstemplate>
                                <rowindicatorcolumn visible="False"><HeaderStyle Width="20px" /></rowindicatorcolumn>
                               
                                <Columns>
                                    <telerik:GridBoundColumn DataField="PermitNumber" HeaderText="Permit #" 
                                        SortExpression="PermitNumber" UniqueName="PermitNumber">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="TermNumber" HeaderText="Term"    
                                        SortExpression="TermNumber" UniqueName="TermNumber">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Mine" HeaderText="Mine"  HeaderStyle-Wrap="false"
                                        SortExpression="Mine" UniqueName="Mine">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="FTypeName" HeaderText="FType"  
                                        SortExpression="FTypeName" UniqueName="FTypeName">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="DistrictAbbrev" HeaderText="District" 
                                        SortExpression="DistrictAbbrev" UniqueName="DistrictAbbrev">
                                    </telerik:GridBoundColumn>                                   
                                    <telerik:GridBoundColumn  DataField="CountyCode" HeaderText="County" 
                                        SortExpression="CountyCode" UniqueName="CountyCode">
                                    </telerik:GridBoundColumn>                                   
                                    <telerik:GridBoundColumn  DataField="Acres" HeaderText="Acres" 
                                        SortExpression="Acres" UniqueName="Acres">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="MineralCode" HeaderText="Min" 
                                        SortExpression="MineralCode" UniqueName="MineralCode">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="TRS" HeaderText="T/R/S" 
                                        SortExpression="TRS" UniqueName="TRS">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="InitialOperation" HeaderText="Issued" 
                                        SortExpression="InitialOperation" UniqueName="InitialOperation">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="TerminationDate" HeaderText="Terminate" 
                                        SortExpression="TerminationDate" UniqueName="TerminationDate">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="PermitStatusCode" HeaderText="Status" 
                                        SortExpression="PermitStatusCode" UniqueName="PermitStatusCode">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="AnnualReportDate" HeaderText="Annual Date" 
                                        SortExpression="AnnualReportDate" UniqueName="AnnualReportDate">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="FSurface" HeaderText="Surface" 
                                        SortExpression="FSurface" UniqueName="FSurface">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="NonFed" HeaderText="NonFed" 
                                        SortExpression="NonFed" UniqueName="NonFed">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="LOMAffected" HeaderText="LOM Affect" 
                                        SortExpression="LOMAffected" UniqueName="LOMAffected">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  DataField="Released" HeaderText="Released" 
                                        SortExpression="Released" UniqueName="Released">
                                    </telerik:GridBoundColumn>

                                </Columns>
                            </mastertableview>
                                   
                            <ClientSettings>
                               <Scrolling AllowScroll="True" UseStaticHeaders="True"  ScrollHeight="100%" />
                            </ClientSettings>
                            <FilterMenu EnableTheming="True" Skin="Vista">
                                <CollapseAnimation Duration="200" Type="OutQuint" />
                            </FilterMenu>
                        </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Sep 2009, 03:02 PM
Hello Macrel,

Unfortunately our PDF engine doesn't support the requested functionality out of the box. You could try to sidestep this limitation by wrapping the contents in a table (width is mandatory in this case):
<telerik:GridBoundColumn DataField="ID" DataFormatString="<table width='500px'><colgroup><col /></colgroup><tr><td>{0}</td></tr></table>" /> 

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Marcel
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or