Hello,
if i try to Export a WebGrid to PDF, the widht of the colums is wrong. All is correct in the WebPage But the table in the PDF is to small. What can i do ?
Freddi
Freddi,
I think you might have answered your own question. If you allow the grid columns to size themselves than the actual width of the grid column is actually zero. Thus, when you 'export' your grid you end up with what looks like extended RowSelectors. What that yak actually is is all the visible grid columns scrunched up as zero width columns.
I solve this by running the grid through a method that sizes the columns 'manually'. Here is the code all ugly and all because this editor (and the web) have a hard time with tabs:
=============================
public class WebGrid
{
int[ aFieldLengths = new int[wg.Columns.Count];
aFieldLengths[col.Index] = 0;
aFieldLengths[col.Index] = col.Header.Caption.Length;
}
aFieldLengths[rowCell.Column.Index] = rowCell.Text.Length;
//Sample MAX_ROWS_TO_SAMPLE for header/field content size
totalFieldLengths += aFieldLengths;
col.Width = Unit.Percentage((double)aFieldLengths[col.Index] / (double)totalFieldLengths); // Unit.Pixel(aFieldLengths[col.Index] * 15);
I know it is a bit of a kludge, but it works till I get more time to finesse it...
Basically, you have to set the Width property of all visible columns in the grid before exporting it. The above code sets that width to the bigger of the column header and the largest column contents within the first MAX_ROWS_TO_SAMPLE rows. I use the first 50 rows in the datasource.