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

ExportToPdf wide grid overflows out of paper

2 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Javier
Top achievements
Rank 1
Javier asked on 26 May 2011, 02:08 AM
Hello, I have a wide RadGrid (> 16 cols) that I am trying to export to PDF.  When I export to PDF, the grid overflows out of the PDF width.  Is there a way to make it use more than 1 page for the width of the table (e.g. 3 pages wide by N pages long)?  I want to get something similar to what I get with the RadReport (in another page I am using the RadReport control and it renders the report 3p wide by N pages long).  Included is the body of the RadGrid and the code-behind in which I format it.  The RadGrid is ajaxified.  Thanks for any help you can provide.

    Private Sub PDFButton_Click(sender As Object, e As System.EventArgs) Handles PDFButton.Click
        _isExport = True
        For Each column As Telerik.Web.UI.GridColumn In ReportGrid.MasterTableView.Columns
            If column.UniqueName = "SelectCheckbox" Or column.UniqueName = "ViewButton" Then
                column.Visible = False
                EndIf
        Next
        ReportGrid.Width = New Unit(22)
        ReportGrid.MasterTableView.ExportToPdf()
    End Sub
  
  
Private Sub ReportGrid_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles ReportGrid.ItemCreated
        If _isExport Then
            If TypeOf (e.Item) Is GridHeaderItem Then
                Dim headerItem As GridHeaderItem = e.Item
                headerItem.Style("font-size") = "8pt"
                headerItem.Style("color") = "white"
                headerItem.Style("background-color") = "gray"
                headerItem.Style("vertical-align") = "bottom"
                For Each cell As TableCell In headerItem.Cells
                    cell.Style("text-align") = "left"
                    cell.Style("font-weight") = "bold"
                    cell.Style("border-color") = "red"
                Next
            ElseIf TypeOf (e.Item) Is GridDataItem Then
                Dim bodyItem As GridDataItem = e.Item
                bodyItem.Style("font-size") = "8pt"
                bodyItem.Style("vertical-align") = "bottom"
                For Each cell As TableCell In bodyItem.Cells
                    cell.Style("text-align") = "left"
                Next
            End If
        End If
    End Sub


<telerik:RadGrid ID="ReportGrid" runat="server" Height="99%" AllowPaging="True" GridLines="None" PageSize="50" AllowSorting="True" AllowFilteringByColumn="false" AllowMultiRowSelection="true" AutoGenerateColumns="false">
    <ClientSettings AllowColumnsReorder="true">
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        <Selecting AllowRowSelect="true" />
        <Resizing AllowColumnResize="true" AllowResizeToFit="false" ClipCellContentOnResize="true" ResizeGridOnColumnResize="true" EnableRealTimeResize="false" />
        <ClientEvents OnRowDeselected="ReportGrid_OnRowDeselected" OnRowSelected="ReportGrid_OnRowSelected" />
    </ClientSettings>
    <MasterTableView>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="SelectCheckbox" HeaderStyle-Width="30" />
            <telerik:GridButtonColumn DataTextField="FullFileName" CommandName="View" ButtonType="ImageButton" UniqueName="ViewButton" ImageUrl="/Images/preview.png" HeaderStyle-Width="30" />
            <telerik:GridBoundColumn DataField="DocArchiveSysKey" DataType="System.String" HeaderText="DocArchiveSysKey" SortExpression="DocArchiveSysKey" UniqueName="DocArchiveSysKey" />
            <telerik:GridBoundColumn DataField="Division" DataType="System.String" HeaderText="Division" SortExpression="Division" UniqueName="Division" />
            <telerik:GridBoundColumn DataField="Route" DataType="System.String" HeaderText="Route" SortExpression="Route" UniqueName="Route" />
            <telerik:GridBoundColumn DataField="Outlet" DataType="System.String" HeaderText="Outlet" SortExpression="Outlet" UniqueName="Outlet" />
            <telerik:GridBoundColumn DataField="OutletName" DataType="System.String" HeaderText="OutletName" SortExpression="OutletName" UniqueName="OutletName" />
            <telerik:GridBoundColumn DataField="DocType" DataType="System.String" HeaderText="DocType" SortExpression="DocType" UniqueName="DocType" />
            <telerik:GridBoundColumn DataField="DisplayDocType" DataType="System.String" HeaderText="DisplayDocType" SortExpression="DisplayDocType" UniqueName="DisplayDocType" />
            <telerik:GridBoundColumn DataField="DocID" DataType="System.String" HeaderText="DocID" SortExpression="DocID" UniqueName="DocID" />
            <telerik:GridBoundColumn DataField="DisplayDocDate" DataType="System.String" HeaderText="DisplayDocDate Date" SortExpression="DisplayDocDate" UniqueName="DisplayDocDate" />
            <telerik:GridBoundColumn DataField="FileName" DataType="System.String" HeaderText="FileName" SortExpression="FileName" UniqueName="FileName" />
            <telerik:GridBoundColumn DataField="FullFileName" DataType="System.String" HeaderText="FullFileName" SortExpression="FullFileName" UniqueName="FullFileName" />
            <telerik:GridBoundColumn DataField="DisplaySettlementDate" DataType="System.DateTime" HeaderText="DisplaySettlementDate" SortExpression="DisplaySettlementDate" UniqueName="DisplaySettlementDate" />
            <telerik:GridBoundColumn DataField="RC2Code" DataType="System.String" HeaderText="RC2Code" SortExpression="RC2Code" UniqueName="RC2Code" />
            <telerik:GridBoundColumn DataField="RC3Code" DataType="System.String" HeaderText="RC3Code" SortExpression="RC3Code" UniqueName="RC3Code" />
            <telerik:GridBoundColumn DataField="RC4Code" DataType="System.String" HeaderText="RC4Code" SortExpression="RC4Code" UniqueName="RC4Code" />
            <telerik:GridBoundColumn DataField="RC5Code" DataType="System.String" HeaderText="RC5Code" SortExpression="RC5Code" UniqueName="RC5Code" />
            <telerik:GridBoundColumn DataField="EA1Code" DataType="System.String" HeaderText="EA1Code" SortExpression="EA1Code" UniqueName="EA1Code" />
            <telerik:GridBoundColumn DataField="EA2Code" DataType="System.String" HeaderText="EA2Code" SortExpression="EA2Code" UniqueName="EA2Code" />
            <telerik:GridBoundColumn DataField="EA3Code" DataType="System.String" HeaderText="EA3Code" SortExpression="EA3Code" UniqueName="EA3Code" />
            <telerik:GridBoundColumn DataField="EA4Code" DataType="System.String" HeaderText="EA4Code" SortExpression="EA4Code" UniqueName="EA4Code" />
            <telerik:GridBoundColumn DataField="EA5Code" DataType="System.String" HeaderText="EA5Code" SortExpression="EA5Code" UniqueName="EA5Code" />
            <telerik:GridBoundColumn DataField="EA6Code" DataType="System.String" HeaderText="EA6Code" SortExpression="EA6Code" UniqueName="EA6Code" />
            <telerik:GridBoundColumn DataField="EA7Code" DataType="System.String" HeaderText="EA7Code" SortExpression="EA7Code" UniqueName="EA7Code" />
            <telerik:GridBoundColumn DataField="EA8Code" DataType="System.String" HeaderText="EA8Code" SortExpression="EA8Code" UniqueName="EA8Code" />
            <telerik:GridBoundColumn DataField="EA9Code" DataType="System.String" HeaderText="EA9Code" SortExpression="EA9Code" UniqueName="EA9Code" />
            <telerik:GridBoundColumn DataField="EA10Code" DataType="System.String" HeaderText="EA10Code" SortExpression="EA10Code" UniqueName="EA10Code" />
        </Columns>
    </MasterTableView>
    <ExportSettings HideStructureColumns="true" ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
        <Pdf PageWidth="11in" PageHeight="8.5in" PageLeftMargin=".5in" PageRightMargin=".5in" PageTopMargin=".5in" PageBottomMargin=".5in" AllowCopy="true" AllowModify="true" AllowPrinting="true" />
    </ExportSettings>
</telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 May 2011, 06:00 AM
Hello Javier,

I also faced the same issue. You can overcome this by setting the page Height and Width before exporting to pdf.

VB:
Protected Sub Button2_Click(sender As Object, e As EventArgs)
    isExport = True
    For Each column As GridColumn In RadGrid1.MasterTableView.Columns
        If column.UniqueName = "EmpId" Then
            column.Visible = False
            RadGrid1.Width = New Unit(22)
        End If
    Next
    RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse("162mm")
    RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse("600mm")
    RadGrid1.MasterTableView.ExportToPdf()
End Sub

Check the following documentation which explains more about this.
PDF export.

Thanks,
Princy.
0
Javier
Top achievements
Rank 1
answered on 26 May 2011, 03:27 PM
Thanks for the reply, but I am still having the same problem.  In the sample code you posted the page size is 162mm x 600mm (6.375in x 23.61in), which is why everything fits in one page.  I tried that and indeed it all fits but it is not a standard paper size.  If I change the size to letter, it does not split the grid across pages.  I changed the code to use Legal paper landscape as shown below:

Private Sub PDFButton_Click(sender As Object, e As System.EventArgs) Handles PDFButton.Click
    _isExport = True
    For Each column As Telerik.Web.UI.GridColumn In ReportGrid.MasterTableView.Columns
        If column.UniqueName = "SelectCheckbox" Or column.UniqueName = "ViewButton" Then
            column.Visible = False
        End If
    Next
    ReportGrid.ExportSettings.Pdf.PageHeight = Unit.Parse("216mm")
    ReportGrid.ExportSettings.Pdf.PageWidth = Unit.Parse("356mm")
    ReportGrid.ExportSettings.Pdf.PageBottomMargin = Unit.Parse("13mm")
    ReportGrid.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("13mm")
    ReportGrid.ExportSettings.Pdf.PageRightMargin = Unit.Parse("13mm")
    ReportGrid.ExportSettings.Pdf.PageTopMargin = Unit.Parse("13mm")
    ReportGrid.MasterTableView.ExportToPdf()
End Sub

What I am looking for is the grid printing in several pages wide (e.g. 5 cols in the 1st page, 5 in the 2nd page, 6 in the 3rd page) just like the RadReport does.  Is the RadGrid export to PDF capable of doing this?
Tags
Grid
Asked by
Javier
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Javier
Top achievements
Rank 1
Share this question
or