Foros del Web » Programación para mayores de 30 ;) » .NET »

[SOLUCIONADO] ITextSharp Lineas Escritas en Archivo PDF

Estas en el tema de ITextSharp Lineas Escritas en Archivo PDF en el foro de .NET en Foros del Web. Buenas Tardes compañeros, adjunto mi código. Me gustaría saber como puedo hacer, para que las líneas no salgan de esta manera, y puedan tener un ...
  #1 (permalink)  
Antiguo 16/02/2015, 16:26
 
Fecha de Ingreso: julio-2013
Mensajes: 36
Antigüedad: 10 años, 9 meses
Puntos: 1
ITextSharp Lineas Escritas en Archivo PDF

Buenas Tardes compañeros, adjunto mi código.

Me gustaría saber como puedo hacer, para que las líneas no salgan de esta manera, y puedan tener un margen donde puedan bajarse y quedar por así decirles en 3 lineas y no solo en 1.


Código:
        Dim l As Integer
        Dim arreglosi(35) As Boolean
        Dim consulta = (From dt In db.criteriosResps Order By dt.idcriterio Where dt.idsnip = txtsnip.Text Select dt.RSi).ToList
        Dim consulta2 = (From da In db.criterios Select da.Nombre).ToList
        Dim x As Integer
        Dim y As Integer = 720
        For Each cri In consulta2
            y = y - 15
            cb.ShowTextAligned(0, cri, 50, y, 0)
        Next
        y = 720
        For Each l In consulta
            If l = False Then
                y = y - 15
                cb.ShowTextAligned(1, "No", 250, y, 0)
            Else
                y = y - 15
                cb.ShowTextAligned(1, "Si", 250, y, 0)

            End If
        Next
Les Coloco la Imágen:
http://prntscr.com/6612gt
  #2 (permalink)  
Antiguo 16/02/2015, 19:05
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Respuesta: ITextSharp Lineas Escritas en Archivo PDF

Creando una tabla y celdas:

Dim pdfTablaCadenaSello As New PdfPTable(1)
Dim arrAnchosColumna2 As Single() = {460.0F} 'PageSize.LETTER.Width
'Dim arrAnchosColumna As Single() = {60.0F, 335.0F, 68.0F, 68.0F}
pdfTablaCadenaSello.SetTotalWidth(arrAnchosColumna 2)
pdfTablaCadenaSello.SpacingBefore = 15.0F 'Give some space after the text or it may overlap the table

PdfPCell = New PdfPCell(New Phrase(New Chunk("Sello digital del CFDI: " & selloCFD, font8)))
pdfTablaCadenaSello.AddCell(PdfPCell)

PdfPCell = New PdfPCell(New Phrase(New Chunk("Sello digital del SAT: " & selloSAT, font8)))
pdfTablaCadenaSello.AddCell(PdfPCell)

PdfPCell = New PdfPCell(New Phrase(New Chunk("Cadena original del complemento de certificacion del SAT: " & cadenaOriginalTimbrado, font8)))
pdfTablaCadenaSello.AddCell(PdfPCell)

' define la posicion a donde se imprimiran los datos cadena y sello
' rowstart, rowend, xpos, ypos
pdfTablaCadenaSello.WriteSelectedRows(0, -1, 130, 110, pdfContentByte)
  #3 (permalink)  
Antiguo 19/02/2015, 09:09
 
Fecha de Ingreso: julio-2013
Mensajes: 36
Antigüedad: 10 años, 9 meses
Puntos: 1
Respuesta: ITextSharp Lineas Escritas en Archivo PDF

Muchas Gracias WWWmaster, con lo que me has dicho he podido hacer lo que necesitaba ahora bien...

tengo un problema y es la posición de la tabla, te adjunto mi código.

Código:
  Dim DocumentoPDF As New Document
        Dim ruta As String = "C:\Users\francisco.lara\Desktop\pdf\libro.pdf"
        Dim fs As New FileStream(ruta, FileMode.Create, FileAccess.Write)
        Dim pdfw As PdfWriter = PdfWriter.GetInstance(DocumentoPDF, fs)

        Dim iEstado As Integer = 0, iColumna As Integer = 0
        '  Const INTERLINEADO As Single = 8
        'Const MARGEN_INFERIOR As Single = 30
        DocumentoPDF.Open()
        DocumentoPDF.NewPage()
        '   cb.BeginText()
        Dim imagen As iTextSharp.text.Image 'declaración de imagen
        imagen = iTextSharp.text.Image.GetInstance(My.Application.Info.DirectoryPath & "\Logo Segeplan a color.jpg") 'nombre y ruta de la imagen a insertar
        imagen.ScalePercent(16.7) 'escala al tamaño de la imagen
        imagen.SetAbsolutePosition(40, 760) 'posición en la que se inserta. 40 (de izquierda a derecha). 500 (de abajo hacia arriba)
        DocumentoPDF.Add(imagen) 'se agrega la imagen al documento
        Dim arreglo(35)
        Dim arreglo2(35)
        Dim arreglo3(35)
        Dim arreglo4(35)

        Dim y As Integer = 720
        Dim pdfTablaCadenaSello As New PdfPTable(4)
        Dim arrAnchosColumna As Single() = {300.0F, 68.0F, 68.0F, 68.0F}
        pdfTablaCadenaSello.SetTotalWidth(arrAnchosColumna)
        pdfTablaCadenaSello.SpacingBefore = 15.0F 'Give some space after the text or it may overlap the table
        pdfTablaCadenaSello.DefaultCell.Border = 0

        Dim i, a, C, D As Integer
        Dim consulta = (From dt In db.criteriosResps Order By dt.idcriterio Where dt.idsnip = txtsnip.Text Select dt.RSi).ToList
        Dim consulta2 = (From da In db.criterios Select da.Nombre).ToList
        Dim consulta3 = (From da In db.criteriosResps Order By da.idcriterio Where da.idsnip = txtsnip.Text Select da.RNo).ToList
        Dim consulta4 = (From da In db.criteriosResps Order By da.idcriterio Where da.idsnip = txtsnip.Text Select da.Observacion).ToList

        Dim font12Bold As New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 8.0F, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)
        For Each cri In consulta2
            arreglo(i) = cri
            i = i + 1
        Next
        For Each l In consulta
            If l = False Then
                y = y - 15
                arreglo2(a) = "NO"
                a = a + 1
            Else
                y = y - 15
                arreglo2(a) = "SI"
                a = a + 1
            End If
        Next
        For Each l In consulta3
            If l = False Then
                y = y - 15
                arreglo3(C) = "NO"
                C = C + 1
            Else
                y = y - 15
                arreglo3(C) = "SI"
                C = C + 1
            End If
        Next
        For Each l In consulta4
            y = y - 15
            arreglo4(D) = l
            D = D + 1
        Next
 
        Dim cell = New PdfPCell(New Phrase("Test"))
        cell.Border = 0
        For b As Integer = 0 To 34
            cell.Border = 0
            pdfTablaCadenaSello.DefaultCell.Border = 0
            cell = New PdfPCell(New Phrase(arreglo(b), font12Bold))
            cell.Border = 0
            pdfTablaCadenaSello.AddCell(cell)
            cell = New PdfPCell(New Phrase(arreglo2(b), font12Bold))
            cell.Border = 0
            pdfTablaCadenaSello.AddCell(cell)
            cell = New PdfPCell(New Phrase(arreglo3(b), font12Bold))
            cell.Border = 0
            pdfTablaCadenaSello.AddCell(cell)
            cell = New PdfPCell(New Phrase(arreglo4(b), font12Bold))
            cell.Border = 0
            pdfTablaCadenaSello.AddCell(cell)
        Next
        DocumentoPDF.Add(pdfTablaCadenaSello)
        ' Close the objects
        DocumentoPDF.Close()
        fs.Close()
        If System.IO.File.Exists(ruta) Then
            If MsgBox("Texto convertido a fichero PDF correctamente " + _
                   "¿desea abrir el fichero PDF resultante?",
                   MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                'Abrimos el fichero PDF con la aplicación asociada
                System.Diagnostics.Process.Start(ruta)
            End If
        Else
            MsgBox("El fichero PDF no se ha generado, " + _
                   "compruebe que tiene permisos en la carpeta de destino.",
                   MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
        End If
El problema esque me sale esto:

http://prntscr.com/674ooi

Quiero posicionar obviamente la tabla debajo de la Imagen, si es posible hacerlo, te agradesco me des una orientación.
  #4 (permalink)  
Antiguo 23/02/2015, 00:08
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Respuesta: ITextSharp Lineas Escritas en Archivo PDF

Lo unico que puedo decirte es "prueba y error", al menos asi lo llegue a ubicar yo.

OJO el PARAMETRO XPOS es de "abajo" hacia "arriba", esto es, ves que dice "130", es midiendo del bottom de la hoja. Si lo quisiera posicionar mas alto, le pondria algo como 800

' define la posicion a donde se imprimiran los datos cadena y sello
' rowstart, rowend, xpos, ypos
pdfTablaCadenaSello.WriteSelectedRows(0, -1, 130, 110, pdfContentByte)
  #5 (permalink)  
Antiguo 04/03/2015, 14:31
 
Fecha de Ingreso: julio-2013
Mensajes: 36
Antigüedad: 10 años, 9 meses
Puntos: 1
Respuesta: ITextSharp Lineas Escritas en Archivo PDF

He Solucionado esto, Muchísimas Gracias Podrías ayudarme con una ultima cosa, quiero que el valor de una Variable Global se agregue al PDF, ya que cuenta con un sistema de usuarios y el usuario se guarda en una variable global quiero que en el reporte aparece el nombre de dicho usuario, pero me marca un error, esto fue lo que intente.

Código vb:
Ver original
  1. Dim cb = pdfw.DirectContent
  2.         Dim Col As New ColumnText(cb)
  3.         Col.SetSimpleColumn(60, 20, 500, 70)
  4.          firma.Add(New Phrase(NombredeUsuario)
  5.         Col.AddText(firma)
  6.         Col.Go()

Error de Capa 8
Solucionado:

Código vb:
Ver original
  1. Dim cb = pdfw.DirectContent
  2.         Dim Col As New ColumnText(cb)
  3.         Col.SetSimpleColumn(60, 20, 500, 90)
  4.         firma.Add(New Chunk("   Firma del Receptor", fonttitulo))
  5.         firma.Add(New Phrase("                          Firma de Enterado       ", fonttitulo))
  6.         firma.Add(vbNewLine)
  7.         'Add the paragraph to the ColumnText
  8.        firma.Add(New Paragraph(vbNewLine + Nombreusuario + vbNewLine, font6Bold))
  9.         firma.Add(New Paragraph(Date.Now + vbNewLine, font6Bold))

Pero me dice que hay un error de sobre carga.

Saludos

Última edición por fradalape; 04/03/2015 a las 15:31

Etiquetas: itextsharp, lineas, pdf
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:46.