RadGrid export to PDF Advice

4 posts, 0 answers
  1. Ryan
    Ryan avatar
    2 posts
    Member since:
    Aug 2012

    Posted 03 Aug 2012 Link to this post

    I didn't know exactly where to put this but I discovered something unique about our situation with using Telerik RadGrid and export to PDF in SharePoint 2010.  I am only posting this because I could not directly find the information that we needed but got clues as to what I needed to do, so I thought I would share my experience with others.

    Our circumstances:

    1. We were using a customized SharePoint 2010 setup.
    2. Our data was being automatically exported and updated by Active Directory each night.
    3. All data was being exported into SharePoint lists.

    Our Issue:
    When we would attempt an export to PDF and we were setting the "ignorepaging" to true (as suggested in numerous posts), but we were still getting a Telerik error message.  Doing searches through the system did not give us the exact resolution to the problem so alot of troubleshooting went on to resolve it.

    Our Resolution:

    1. When using a RadGrid in a SharePoint 2010 webpart, check to see if you have a sizing limit as to the number of rows returned per page.  This was true for us because of the amount of data we were pulling and we were limiting the max rows per page to 75 rows and we had close to 300 rows or so being pulled into our RadGrid.
    2. If the above is true, when you export to PDF, you need to set your controls for the look and feel of the pdf, then before you send it to the pdf, ensure that you "rebind" the data prior to exporting it.  This is essential, if you have paging enabled in the RadGrid but you are setting "ignorepaging" to true. 

     

    Example:

    myDataList.ExportSettings.ExportOnlyData = false;
    myDataList.ExportSettings.IgnorePaging = true;
    myDataList.ExportSettings.OpenInNewWindow = true;
    myDataList.ExportSettings.FileName = "Some_Name";
    myDataList.ExportSettings.Pdf.PageWidth = 1200;
    myDataList.Rebind();
    myDataList.MasterTableView.ExportToPdf();
  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 08 Aug 2012 Link to this post

    Hello Ryan,

    Thank you for sharing your solution with the community. By the way, what was the error you mentioned? Can you post it here together with the stack trace if possible?

    Best regards,
    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.

  3. Ryan
    Ryan avatar
    2 posts
    Member since:
    Aug 2012

    Posted 08 Aug 2012 Link to this post

    Here is my stack trace:

    System.InvalidCastException: Unable to cast object of type 'Telerik.Web.Apoc.Layout.BlockArea' to type 'Telerik.Web.Apoc.Layout.AreaContainer'.
    at Telerik.Web.Apoc.Fo.Flow.BlockContainer.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Flow.Block.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area, Region region)
    at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
    at Telerik.Web.Apoc.StreamRenderer.Render(PageSequence pageSequence)
    at Telerik.Web.Apoc.Fo.FOTreeBuilder.EndElement()
    at Telerik.Web.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.SystemException: System.InvalidCastException: Unable to cast object of type 'Telerik.Web.Apoc.Layout.BlockArea' to type 'Telerik.Web.Apoc.Layout.AreaContainer'.
    at Telerik.Web.Apoc.Fo.Flow.BlockContainer.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Flow.Block.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area, Region region)
    at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
    at Telerik.Web.Apoc.StreamRenderer.Render(PageSequence pageSequence)
    at Telerik.Web.Apoc.Fo.FOTreeBuilder.EndElement()
    at Telerik.Web.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [SystemException: System.InvalidCastException: Unable to cast object of type 'Telerik.Web.Apoc.Layout.BlockArea' to type 'Telerik.Web.Apoc.Layout.AreaContainer'. 
    at Telerik.Web.Apoc.Fo.Flow.BlockContainer.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Flow.Block.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area, Region region)
    at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area)
    at Telerik.Web.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
    at Telerik.Web.Apoc.StreamRenderer.Render(PageSequence pageSequence)
    at Telerik.Web.Apoc.Fo.FOTreeBuilder.EndElement()
    at Telerik.Web.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)]
    Telerik.Web.Apoc.ApocDriver.FireApocError(String message) +133
    Telerik.Web.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader) +860
    Telerik.Web.Apoc.ApocDriver.Render(XmlReader inputReader, Stream outputStream) +257
    Telerik.Web.UI.Grid.Export.TableViewExporter.PdfExportRenderForm(HtmlTextWriter nullWriter, Control form) +1194
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115
    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +411
    System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +87
    System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +53
    Telerik.Web.UI.Grid.Export.TableViewExporter.PdfExportRenderPage(HtmlTextWriter nullWriter, Control page) +154
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115
    System.Web.UI.Page.Render(HtmlTextWriter writer) +38
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4240
  4. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 13 Aug 2012 Link to this post

    Hello Ryan,

    The most possible causes of this exception are div elements with either absolute positioning or width/height specified in absolute units (px).
    You could handle the PdfExporting event and examine the output to see if there are any of these.

    Best regards,
    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top