I've implemented this helpful example code (http://demos.telerik.com/silverlight/#GridView/PrintAndExportWithRadDocument) and it is all working as expected, however the table that is created does not take up the whole width of the page. I notice it uses the column widths of the RadGridView, however they are not ideal in the A4 pdf. I would like the table that is created for the pdf to size itself based on content. Is this possible, and if so, how would I do it? I figure it's got something to do with this line:
cell.PreferredWidth =
new
TableWidthUnit((
float
)columns[i].ActualWidth);
Thanks
7 Answers, 1 is accepted
RadGridView exposes the ElementExporting event. Inside the event args you will find a member to control the width of the exported element. Once you subscribe to this event inside the EventHandler you can adjust the width of the columns this way.
In case you meet any troubles while implementing this please let me know.
All the best,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

I'm just getting back to this thread now.
I've looked inside the EventArgs and I see a width property but I'm unsure how to utilise it for my purposes. My PDF button binds similar to the example I followed but I'm also passing in the table as a parameter:
Command="{Binding ExportCommand, Source={StaticResource PrintAndExport}}" CommandParameter="{Binding ElementName=rgvSearchFieldSets}"
I have reviewed this thread and it seems i have mislead you in my first answer. When using the approach from the demo indeed RadGridview will actually not utilize its internal export logic and the event would not fire. Please receive my apologies for the wrong answer.
In order to achieve the results you need you should use TableWidhtUnitType Percent when setting the
cell.PreferredWidth.
Depending on the percentage value , column widths will be distributed proportionally ( similarly to an HTML table) . Regards,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

I've changed the PrefferedWidth to percentage as you've advised,
cell.PreferredWidth =
new
TableWidthUnit(TableWidthUnitType.Percent);
document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
Further on the suggested solution (if I get it to work). By setting a percentage will I then forfeit different widths for each column? For example, one column only contains single numbers, and another long strings, so having them equal width is not ideal.
There are two options for setting the layout of the table.
The table has a property LayoutMode which determines if it should resize its columns depending on its contents, or the columns' width should be fixed. The default value of the property is "Auto", which means that the document will use an internal algorithm to determine the size of the columns.
The properties that allow control over the width of the columns is the preferred width of the cells. You can set it to a value in pixels or as percent - relatively to the size of the whole table. However, you should always provide a numeric value - either the pixel width or the percent value you wish to set. For example, you can set a column's width to 20 percent using the following code:
cell.PreferredWidth =
new
TableWidthUnit(TableWidthUnitType.Percent, 20);
I hope this helps. Greetings,
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

In the example I'm using there a several locations where a PreferredWidth is set (the header cell, the data cell, and an indent cell). I haven't completely got my head around it but I have five columns and I find if I leave the header preferredWidth as it was in pixels but set the PreferredWidth in the AddDataRow method (not the indent) to a percent below 20% it stretches the table but also maintains most of the column widths from the gridView which is what I want. Unfortunately it's still not perfect and it's preventing the class from being as generic (for example I'd get a different appearance if I apply it to a gridview with a different number of columns).
The ideal scenario is for the class to set the widths based on the content of the columns.
Overall, there are two options for creating the table.
You can create a table with fixed layout and setting the PreferredWidth to a value depending on the size of the GridView column. For example, you can calculate a ratio value by dividing the width of the page size by the respective size of the grid view. Afterwards, multiply the width of each column by this ratio factor and use this value as preferred width.
The other option would be to use a table with autofit layout and rely on RadDocument's algorithm to set the widths of the columns depending on their contents.
Please, try these approaches and if you don't manage to accomplish the desired results, attach a demo project in a support ticket, so that we can look into it and provide more specific assistance.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>