Cita:
Iniciado por dwaks No se si el código ese te ayude, pienso que es más para que veas el uso de la libreria y la adaptes a lo que quieras hacer.
Pero deberás programar tu propia forma de uso.
Saludos,
Hola encontre este ejemplo
http://www.aspsnippets.com/post/2009...TextSharp.aspx
pero abre el pdf pero no me muestra nada le dejo una fotos y el codigo escrito.
[IMG]
[/IMG]
[IMG]
[/IMG]
Código PHP:
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html
Imports iTextSharp.text.html.simpleparser
Imports System.Text
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConnString As String = ConfigurationManager.ConnectionStrings("instrumentosConnectionString").ConnectionString
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
Dim sda As New SqlDataAdapter()
Dim ds As New DataSet()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM [subarea]"
cmd.Connection = con
sda.SelectCommand = cmd
End Sub
Protected Sub btnExportPDF_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExportPDF.Click
'Create a table
Dim table As New iTextSharp.text.Table(GridView1.Columns.Count)
table.Cellpadding = 5
'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.A4, 10.0F, 10.0F, 10.0F, 0.0F)
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()
End Sub
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Verifies that the control is rendered
End Sub
Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
End Class
Espero ayuda. saludos