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

Exporting to PDF, column width issue.

4 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 10 Dec 2012, 03:07 PM
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?

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 10 Dec 2012, 04:18 PM
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.

0
Mike
Top achievements
Rank 1
answered on 10 Dec 2012, 09:46 PM
Turn off column virtualization does the trick. Thank you.
0
Jacob
Top achievements
Rank 1
answered on 27 Dec 2016, 01:20 PM

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!

0
Jacob
Top achievements
Rank 1
answered on 29 Dec 2016, 09:56 AM

I have found a workaround by adding this line

new GridViewDocumentExportOptions()
                    {
                        AutoFitColumnsWidth = true,

 

thank you!

Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Mike
Top achievements
Rank 1
Jacob
Top achievements
Rank 1
Share this question
or