Exporting to PDF, column width issue.

5 posts, 0 answers
  1. Mike
    Mike avatar
    23 posts
    Member since:
    Jun 2012

    Posted 10 Dec 2012 Link to this post

    Hi,

    I have an issue exporting a gridview to pdf when the gridview has a horizontal scrollbar and is wider than the container.

    If I export without scrolling, the columns on the right hand side do not have their actual widths set properly, and are much less wide than the other columns. However, if I first scroll the scroll bar, and then scroll it back, when I export, the columns are the correct width.

    Is there a way to programmatically do this? Is there a call on the gridview to auto size or best fit the columns or something like that? Do the columns actually have to be displayed on screen for the export to have the actual widths set?
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 10 Dec 2012 Link to this post

    Hello Mike,

    I guess the problematic columns are sized "Auto" . For such columns RadGridView relies on the Measure and Arrange layout passes to determine the width of the column .

    In order to get more accurate results you may need to turn off the column virtualization .

    Regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Mike
    Mike avatar
    23 posts
    Member since:
    Jun 2012

    Posted 10 Dec 2012 Link to this post

    Turn off column virtualization does the trick. Thank you.
  4. Jacob
    Jacob  avatar
    33 posts
    Member since:
    Apr 2016

    Posted 27 Dec 2016 Link to this post

    hello Pavel,

    I know this is quite old, but i just can't seem to make it work with my current code. Is there something i am missing here?

    private void ExportToPdfClick(object obj)
    {
        var file = System.IO.Path.Combine(Path.GetTempPath(), ExportDefaultSaveName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf");
        EnableColumnVirtualization = false;
        using (Stream stream = File.Create(file))
        {
            this.ExportToPdf(stream,
                new GridViewDocumentExportOptions()
                {
                    ShowColumnFooters = true,
                    ShowColumnHeaders = true,
                    ShowGroupFooters = true
                });
        }
        EnableColumnVirtualization = true;
        Process.Start(file);
    }

     

    Thank you!

  5. Jacob
    Jacob  avatar
    33 posts
    Member since:
    Apr 2016

    Posted 29 Dec 2016 in reply to Jacob Link to this post

    I have found a workaround by adding this line

    new GridViewDocumentExportOptions()
                        {
                            AutoFitColumnsWidth = true,

     

    thank you!

Back to Top