Working with ExportToPdf()

8 posts, 0 answers
  1. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 10 Feb 2009 Link to this post

    Hi guys,

    Every now and then I get this error message in FF when trying to export a radGrid to pdf:

    XML Parsing Error: no element found
    Location: http://localhost/etc/etc
    Line Number 1, Column 1:
    ^


    When this occurs, IE is however just displays a blank page.

    When this has happened I've been able to backtrack any recent changes in my code, and continued from there. I wasn't so lucky this last time. I've actually commented out every single settings, so I'm basically just making a dry call: RadGrid1.MasterTableView.ExportToPdf()

    Still the error exists.

    I searched the forums but didn't find any info on this, does anyone have an idea just what might be going on?

    Regards,
    -DJ-



  2. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 12 Feb 2009 Link to this post

    I wasn't using the most recent build, now I've updated and I get a new error, this time it's a .net error:

    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.TableCell.Layout(Area area)
      at Telerik.Web.Apoc.Fo.Flow.TableRow.Layout(Area area)
      at Telerik.Web.Apoc.Fo.Flow.AbstractTableBody.Layout(Area area)
      at Telerik.Web.Apoc.Fo.Flow.Table.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)


    Seems to be a blast from the past, all I could find was this ancient thread: http://www.telerik.com/community/forums/aspnet/grid/exception-on-pdf-export-from-grid.aspx

    Any ideas?
    -DJ-
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 12 Feb 2009 Link to this post

    Hello DJ,

    You can handle the Pdf_Exporting event and then check whether the generated output is XHTML compliant.
    protected void RadGrid1_PdfExporting(object source, GridPdfExportingArgs e) 
        e.RawHTML; //copy the contents of this property 

    W3C Markup Validation Service

    Alternatively you can send us a simplified working version of your project. In this way we will be able to debug it locally and provide more to-the-point answer for you.

    Best regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 12 Feb 2009 Link to this post

    Hi Daniel,

    Thanks for the info.
    I've made some progress and discovered the source of the error.

    I'm calling a global sub which contains settings & translations for the grid.
    This results in errors when trying to export to pdf (not .doc or .xls)

    So, I've tried setting these properties only my boolean bolisExport = False but haven't been able to find a proper time in the lifecycle to get this working.

    It's always too early or too late it seems.

    I'll have to spend some more time on this.

    Regards,
    -DJ-
  6. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 14 Feb 2009 Link to this post

    Imagine this scenario:

    Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
        Call SetupGrid(RadGrid1)
    End Sub

    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        .... databind code....
    End Sub

    Protected Sub ExportGrid(ByVal s As Object, ByVal e As EventArgs)
        bolIsExport = True
        .... settings for the export ....
    End Sub

    Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
        If bolIsExport = True Then
        .... more settings for export....
    End Sub




    Then in the app_code folder we have the setupGrid function:

    Public Shared Sub SetupGrid(ByVal grid As RadGrid)

        grid.ClientSettings.ClientMessages.PagerTooltipFormatString = "Síða {0} af {1}" ' Causes breakdown every time in pdf export
        grid.ClientSettings.ClientMessages.PagerTooltipFormatString = "Síða {0} af {1}" ' Causes breakdown every now and then in pdf export
        grid.PagerStyle.Mode = GridPagerMode.Slider ' causes breakdown every now and then in pdf export

        .... other settings, most of which can crash the application....
    End Sub

    So, basically just calling the setupGrid causes breakdown in execution. It does not even matter when it's called. For example, if it's called in LoadComplete or Prerender, it's too late to actually influence the grid itself, yet it still causes errors.

    It's not an option setting the grid's properties manually within each page as my application has dozens of grids that need to  keep a universal look & feel. The only option left is not to use the pdf export function and just stick to word and excel.

    Regards,
    -DJ-






  7. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 14 Feb 2009 Link to this post

    Imagine adding one line to the ExportGrid Sub and suddenly seeing everything working as expected.

        RadGrid1.AllowFilteringByColumn = False

    No more errors.

    Regards,
    -DJ-
  8. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 17 Feb 2009 Link to this post

    The saga continues, and the excitement grows.

    For those who run into trouble with the ExportToPdf() function I'll continue posting my findings.

    Here is one little catch 22 quirk.

    If you are rebinding your grid before exporting it, and you set
        RadGrid1.AllowPaging = False
    then RadGrid1.ExportSettings.IgnorePaging = False has no effect, since the grid is displayed as a whole.

    However, if you set AllowPaging to True (at least if the pagermode is set to slider) you get an error.

    The solution is to set the pagerstyle  to invisible:
    RadGrid1.PagerStyle.Visible = False

    Some of these things might seem logical enough, but since the error messages are utterly useless it needs to be documented.

    Regards,
    -DJ-

  9. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 18 Feb 2009 Link to this post

    Hello DJ,

    Thank you for the clarification. We are currently investigating this case. As a sign of gratitude for your cooperation I updated your Telerik points.

    Keep up the good work.

    Best regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017