I cannot for some reason set left and right margins for itextsharp gridview to pdf conversion. Everytime i generate PDF document the margins are .5 inches and will not change no matter what numbers i plug in into document(). Please help. Here is my code:
GridView1.AllowPaging = False
GridView1.DataBind()
'Create a table
Dim table As New iTextSharp.text.Table(GridView1.Columns.Count)
table.Cellpadding = 1
'Set the column widths
Dim widths As Integer() = New Integer(GridView1.Columns.Count - 1) {}
For x As Integer = 0 To GridView1.Columns.Count - 1
widths(x) = CInt(GridView1.Columns(x).ItemStyle.Width.Value)
Dim cellText As String = _
Server.HtmlDecode(GridView1.HeaderRow.Cells(x).Text)
Dim cell As New iTextSharp.text.Cell(cellText)
cell.BackgroundColor = _
New Color(System.Drawing.ColorTranslator.FromHtml("#008000"))
table.AddCell(cell)
Next
table.SetWidths(widths)
'Transfer rows from GridView to table
For i As Integer = 0 To GridView1.Rows.Count - 1
If GridView1.Rows(i).RowType = DataControlRowType.DataRow Then
For j As Integer = 0 To GridView1.Columns.Count - 1
Dim cellText As String = _
Server.HtmlDecode(GridView1.Rows(i).Cells(j).Text)
Dim cell As New iTextSharp.text.Cell(cellText)
'Set Color of Alternating row
If i Mod 2 <> 0 Then
cell.BackgroundColor = _
New Color(System.Drawing.ColorTranslator.FromHtml("#C2D69B"))
End If
table.AddCell(cell)
Next
End If
Next
'Create the PDF Document
Dim pdfDoc As New Document(PageSize.LETTER, 10, 10, 36, 36)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
pdfDoc.Add(table)
pdfDoc.Close()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", _
"attachment;filename=GridViewExport.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Write(pdfDoc)
Response.End()