Usuario
AYUDA EXPORTAR FORMULARIO A UN PDF

Pregunta
-
Saludos a todos... Estoy trabajando en mi primer proyecto con visual estudio y asp.net... Tengo el siguiente problema a solucionar
Tengo un formulario el consta de varias cajas de textos y un gridview con datos... algo así...
entre los campo que tengo en el formulario tengo DropDownList con el cual al seleccionar un dato muestro en el gridview los datos que pertenecen a el... pueden ser 1 o mas datos... el problema que tengo es exportar ese formulario a un archivo en PDF... todo va bien con las cajas de texto pero no me muestra el gridview en el pdf... estoy utilizando la librería itextsharp... el código k tengo es el siguiente
Protected Sub ButtonReporte_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonReporte.Click
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=Facturacion.pdf")
FillPDF(Server.MapPath("ModeloFacturaFidec.pdf"), Response.OutputStream)
End Sub
Public Sub FillPDF(ByVal template As String, ByVal stream As Stream)
obtNomEPS()
Dim reader As New PdfReader(template)
Dim stamp As New PdfStamper(reader, stream)
stamp.AcroFields.SetField("NumFact", tbxNumFactura.Text)
stamp.AcroFields.SetField("FechaFact", tbxFechaFactura.Text)
stamp.AcroFields.SetField("EPS", tbxnombreEPS.Text.ToString)
stamp.AcroFields.SetField("NitEps", tbxCodNit.Text)
stamp.AcroFields.SetField("DirEPS", tbxDireccion.Text)
stamp.AcroFields.SetField("TelEPS", tbxTelefonos.Text)
stamp.AcroFields.SetField("NomPaciente", tbxNomPaciente.Text)
Dim table = New PdfPTable(5)
'Dim celda = New PdfPCell(("Header abarca tres columnas"))
For Each row As GridViewRow In GridViewDetaFact.Rows
table.AddCell(row.Cells(1).Text)
table.AddCell(row.Cells(2).Text)
table.AddCell(CType(row.FindControl("textbox1"), TextBox).Text)
table.AddCell(CType(row.FindControl("textbox2"), TextBox).Text)
table.AddCell(CType(row.FindControl("lblTotal"), TextBox).Text)
Next
'stamp.AcroFields.SetField("subTotal", txbSubTotal.Text)
stamp.AcroFields.SetField("Descuento", tbxDescuento.Text)
stamp.AcroFields.SetField("total", tbxTotal.Text)
stamp.AcroFields.SetField("vlLetras", tbxVlLetras.Text)
stamp.FormFlattening = True
stamp.Close()
End SubGracias por su colaboración...
Todas las respuestas
-
que eso de AcroFields, porque no usas una libreria de .ent para esta accion como ser
iTextSharp
iTextSharp - Introducing Tables
Leandro Tuttini
Blog
Buenos Aires
Argentina -
Tengo este codigo
Public Sub FillPDF()
Dim Rutaarchivo As String = "C:\Users\W7\Desktop\Facturas\Factura.pdf"
Dim docum As New Document
Dim pdfw As PdfWriter
Dim cb As PdfContentByte
Dim imagenlogo As iTextSharp.text.Image 'Declaración de una imagen
Dim fuente As iTextSharp.text.pdf.BaseFont
docum = New Document(PageSize.LEDGER, 0, 0, 100, 20)
Try
pdfw = PdfWriter.GetInstance(docum, New FileStream(Rutaarchivo, FileMode.Create, FileAccess.Write, FileShare.None))
Dim tablaHeader As New Table(6)
tablaHeader.DefaultHorizontalAlignment = 1
Dim tablaGrilla As New Table(5)
tablaGrilla.DefaultHorizontalAlignment = 1
Dim tablaFooter As New Table(4)
tablaFooter.DefaultHorizontalAlignment = 1
docum.Open()
cb = pdfw.DirectContent
docum.NewPage()
cb.BeginText()
fuente = FontFactory.GetFont(FontFactory.TIMES_ROMAN, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL).BaseFont
cb.SetFontAndSize(fuente, 24)
cb.SetColorFill(iTextSharp.text.Color.BLACK)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "FUNDACION INTERNACIONAL PARA EL\nDESARROLLO DE LAS COMUNIDADES FIDEC\nCentro de Rehabilitacion Infantil IPS\nLuis David Caro Wagner\nNit: 824003334-8\nResolucion DIAN No. 20000106719\nFecha 2009.09.02 Numeracion del 1 al 10000", 600, PageSize.LEDGER.Height - 60, 0)
cb.EndText()
pdfw.Flush()
'************** TABLA Header *****************************
'Se especifica las celdas de la tabla
Dim thcell1 As New Cell("Factura Venta")
Dim thcell2 As New Cell("Fecha Factura")
Dim thcell3 As New Cell("Señores")
Dim thcell4 As New Cell("No. Nit")
Dim thcell5 As New Cell("Direccion")
Dim thcell6 As New Cell("Telefono")
Dim thcell7 As New Cell("Nombre del Paciente")
'se le da formato a las celda
thcell1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
thcell2.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
thcell3.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
thcell4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
thcell5.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
thcell6.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
thcell7.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
'se agregan las celdas a la tabla
tablaHeader.AddCell(thcell1)
tablaHeader.AddCell(thcell2)
tablaHeader.AddCell(thcell3)
tablaHeader.AddCell(thcell4)
tablaHeader.AddCell(thcell5)
tablaHeader.AddCell(thcell6)
tablaHeader.AddCell(thcell7)
'se le asigana valor a las celdas
tablaHeader.AddCell(tbxNumFactura.Text.ToString)
tablaHeader.AddCell(tbxFechaFactura.Text.ToString)
tablaHeader.AddCell(tbxnombreEPS.Text.ToString)
tablaHeader.AddCell(tbxCodNit.Text.ToString)
tablaHeader.AddCell(tbxDireccion.Text.ToString)
tablaHeader.AddCell(tbxTelefonos.Text.ToString)
tablaHeader.AddCell(tbxNomPaciente.Text.ToString)
'************** TABLA GRILLA *****************************
Dim tgcell1 As New Cell("Codigo")
Dim tgcell2 As New Cell("Descripcion")
Dim tgcell3 As New Cell("Vl. Unitario")
Dim tgcell4 As New Cell("Cantidad")
Dim tgcell5 As New Cell("Total")
tgcell1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
tgcell2.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
tgcell3.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
tgcell4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
tgcell5.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY
tablaGrilla.AddCell(tgcell1)
tablaGrilla.AddCell(tgcell2)
tablaGrilla.AddCell(tgcell3)
tablaGrilla.AddCell(tgcell4)
tablaGrilla.AddCell(tgcell5)
For Each row As GridViewRow In GridViewDetaFact.Rows
tablaGrilla.AddCell(row.Cells(1).Text)
tablaGrilla.AddCell(row.Cells(2).Text)
tablaGrilla.AddCell(CType(row.FindControl("textbox1"), TextBox).Text)
tablaGrilla.AddCell(CType(row.FindControl("textbox2"), TextBox).Text)
tablaGrilla.AddCell(CType(row.FindControl("lblTotal"), TextBox).Text)
Next
' **************************************************
tablaHeader.Cellpadding = 1
tablaGrilla.Cellpadding = 1
'se agregan las tablas al documento
docum.Add(tablaHeader)
docum.Add(tablaGrilla)
docum.Add(tablaFooter)
docum.PageSize.Rotate()
docum.Close()
Label1.Text = "PDF creado satisfactoriamente"
System.Diagnostics.Process.Start("C:\Users\W7\Desktop\Facturas\Factura.pdf") 'Abre el archivo
Catch ex As Exception
Throw New Exception("Error al generar archivo PDF (" & ex.Message & ")")
End Try
pdfw = Nothing
docum = Nothing
End Subque le falta para que me salga el documento generado vertical "no horizontal" como me sale...
2. como hago para poner espacio entre las tablas.
3. como hago para que el titulo no me salga en una sola linea si no en varias ya que es muy largo
sugerencias por favor...
- Editado webcarlosf lunes, 10 de septiembre de 2012 20:18