Help with iTextsharp

Last post 11-21-2009 4:49 PM by TATWORTH. 2 replies.

Sort Posts:

  • Help with iTextsharp

    11-11-2009, 4:37 PM
    • Member
      1 point Member
    • uniquealex
    • Member since 07-10-2009, 9:52 PM
    • Posts 14

    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()
     

  • Re: Help with iTextsharp

    11-16-2009, 11:46 AM
    • Member
      1 point Member
    • uniquealex
    • Member since 07-10-2009, 9:52 PM
    • Posts 14

    Can anybody at least suggest either another forum where i could ask about textsharp or another library i could use.

     

    Thank you. 

  • Re: Help with iTextsharp

    11-21-2009, 4:49 PM
    • All-Star
      62,769 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 8:34 AM
    • England
    • Posts 12,247
    • TrustedFriends-MVPs

    For iTextSharp questions, pleaser ask at:

    http://www.nabble.com/iTextSharp-f4188.html

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (3 items)