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

Need help with exporting to pdf

2 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 23 Sep 2011, 06:40 AM
Hi,
I've spent all day trying to get RadGrid to export to pdf with formatting, there are so many problems I can not resolve, my codes are based on : http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/pdfexport/defaultcs.aspx
Here is my ItemCreated event handler:
void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (isPdfExport)
    {
        GridItem item = e.Item as GridItem;
        switch (item.ItemType) //Mimic RadGrid appearance for the exported PDF file
        {
            case GridItemType.Item:
                item.Style["background-color"] = "#ffffff";
                item.Style["font-size"] = "12px";
                item.Cells[2].Style["width"] = "50px";
                break;
            case GridItemType.AlternatingItem:
                item.Style["background-color"] = "#eeeeee";
                item.Cells[2].Style["width"] = "50px";
                item.Style["font-size"] = "12px";
                break;
            case GridItemType.Header:
                for (int i = 0; i < item.Cells.Count; i++)
                {
                    item.Cells[2].Style["width"] = "50px";
                    item.Cells[i].Style["text-align"] = "left";
                    item.Cells[i].Style["background-color"] = "#010101";
                    item.Cells[i].Style["color"] = "#ffffff";
                }
                break;
            case GridItemType.Footer:
            case GridItemType.GroupHeader:
            case GridItemType.GroupFooter:
                break;
        }
    }
}
The major problems I have:
(1) Width does not work at all, every column has equal width on exported pdf no matter how I set them.
(2) Contents do not wrap, if the data source has columns to long to be fitted in a row, they got truncated or overlap with next column.
(3) Sometimes it simply throws exceptions if the data source has lengthy data, I suspect the data might contain html tags.
(4) How do I control the boders? I tried Style["border"] = "1px solid #000", no effects at all. 

Please help     

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Sep 2011, 01:46 PM
Hi Ed,

Straight to your questions.
1) To set the width you can go through the following code.

C#:
protected void grid1_GridExporting(object sender, GridExportingArgs e)
{
  GridColumn gridCol = RadGrid1.MasterTableView.GetColumn("LastName");
  gridCol.HeaderStyle.Width = Unit.Pixel(100);
}

2) There is no way to achieve text wrapping since there is a limitation in the PDF export engine.
You can just go through the suggestions listed in "How to fit XX columns on my page?" Q&A section of the following document.
PDF Export Q & A

3) I have tried to replicate the issue but no avail.Please elaborate your scenario.

4) You can achieve the border by setting the pagewidth and pageheight properties appropriately with the style attribute. 


Thanks,
Princy.
0
Daniel
Telerik team
answered on 26 Sep 2011, 03:53 PM
Hello Ed and Princy,

To points 2 and 3:
Contents do not wrap, if the data source has columns to long to be fitted in a row, they got truncated or overlap with next column.
The overflowing content will be automatically carried over the next row provided that you have whitespace characters inside.

Sometimes it simply throws exceptions if the data source has lengthy data, I suspect the data might contain html tags.
Please post the full stack trace here. It might help us find out what is wrong.

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
Tags
Grid
Asked by
Ed
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or