tags:

views:

50

answers:

0

Hi everyone, I'm having trouble with the following code. I'm trying to add a gridview to a PDF document, and I want the table to be only as wide as the gridview itself.

Right now, I've hard coded 700 into the rectangle, to try and set a max width for the table. The odd thing is, the bigger the number (let's say 800) the smaller the table will get. So essentially, the smaller the number (200), the table will go beyond a 8x11 sheet of paper.

Does anyone know a solution? Or should I clarify anything else?

pageDocument = new Rectangle(**700**, (float)gvGrid.Height.Value);
table = this.GridViewTable(gvGrid, headerTable, tableName, tableNameAlignment);

paragraph = new Paragraph();
paragraph.SpacingAfter = 10f; //spacing that will be used between each table
paragraph.Alignment = Element.ALIGN_CENTER;

paraTable = new float[table.NumberOfColumns];

colWidth = Math.Round((double)(gvGrid.Width.Value / table.NumberOfColumns), 0, MidpointRounding.AwayFromZero);

for (int i = 0; i < table.NumberOfColumns; i++)
{
    paraTable[i] = (float)colWidth;
}

table.SetWidthPercentage(paraTable, pageDocument);

paragraph.Add(table);
Doc.Add(paragraph);