How can I assign a position to a table with iTextSharp?

1

I am making a report with the itextsharp library and I need to place a table that is always at the end of the file, regardless of whether it is full or not.

Annex my code. The error it gives me is the following: "Unhandled exception of type 'System.StackOverflowException' in mscorlib.dll" (the error marks it in the part of up to the bottom of the method where it says file.Add (Tpie))

Public Class itsEvents

Inherits PdfPageEventHelper
Public Overrides Sub OnStartPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal docume As iTextSharp.text.Document)
    Dim imagen As iTextSharp.text.Image 'declaración de imagen
    Dim textdwn As Font = FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD)
    Dim Tcabecera As New PdfPTable(3) 'tabla  para cabecera
    Dim Ttitulo As New PdfPTable(6) 'tabla para el titulo y datos generales
    Dim salto As Font = FontFactory.GetFont(FontFactory.HELVETICA, 6)
    Dim saltoF As Font = FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.BOLD)
    Dim fchica As Font = FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD)
    Dim Ftitulo As Font = FontFactory.GetFont(FontFactory.TIMES, 14, Font.BOLD)



    'Agregar escabezado, el que queramos 
    imagen = iTextSharp.text.Image.GetInstance("C:\Users\marco\Dropbox\SoftwareITSCH\Images\encabezado2.jpg") 'nombre y ruta de la imagen a insertar
    imagen.ScalePercent(35) 'escala al tamaño de la imagen
    imagen.Alignment = iTextSharp.text.Image.ALIGN_CENTER




    'PARTE SUPERIOR DEL DOCUMENTO (MEMBRETADO, FECHA Y DATOS GENERALES)
    Tcabecera.WidthPercentage = 100
    Dim anchoTcabecera() As Single = {1, 98, 1}
    Tcabecera.SetWidths(anchoTcabecera)

    Dim margen As New PdfPCell(New Phrase(" ", salto))
    margen.Colspan = 3
    margen.BorderWidth = 0
    Tcabecera.AddCell(margen)

    Dim espacio As New PdfPCell(New Phrase(" "))
    espacio.Colspan = 1
    espacio.BorderWidth = 0
    Tcabecera.AddCell(espacio)

    Dim img As New PdfPCell(imagen)
    img.HorizontalAlignment = Element.ALIGN_CENTER
    img.BorderWidth = 0
    Tcabecera.AddCell(img)

    Tcabecera.AddCell(espacio)

    Ttitulo.WidthPercentage = 100
    Dim anchoTtitulo() As Single = {1, 28, 45, 10, 15, 1}
    Ttitulo.SetWidths(anchoTtitulo)

    Dim saltoTitulo As New PdfPCell(New Phrase(" ", salto))
    saltoTitulo.Colspan = 6
    saltoTitulo.BorderWidth = 0
    Ttitulo.AddCell(saltoTitulo)

    Ttitulo.AddCell(espacio)
    Ttitulo.AddCell(espacio)
    Ttitulo.AddCell(espacio)
    Dim Memb As New PdfPCell(New Phrase("TECNOLOGICO NACIONAL DE MEXICO" + vbCrLf + "Instituto Tecnológico Superior de Ciudad Hidalgo.", fchica))
    Memb.Colspan = 2
    Memb.BorderWidth = 0
    Memb.HorizontalAlignment = Element.ALIGN_CENTER
    Ttitulo.AddCell(Memb)
    Ttitulo.AddCell(espacio)

    Ttitulo.AddCell(espacio)
    Dim Titulo As New PdfPCell(New Phrase("RESGUARDO DE MOBILIARIO, HERRAMIENTAS Y MAQUINARIA ", Ftitulo))
    Titulo.Colspan = 4
    Titulo.BorderWidth = 0
    Titulo.HorizontalAlignment = Element.ALIGN_CENTER
    Ttitulo.AddCell(Titulo)
    Ttitulo.AddCell(espacio)

    Dim saltoL As New PdfPCell(New Phrase(" ", salto))
    saltoL.Colspan = 6
    saltoL.BorderWidth = 0
    Ttitulo.AddCell(saltoL)


    Ttitulo.AddCell(espacio)
    Dim Dependencia As New PdfPCell(New Phrase("DEPENDENCIA O ENTIDAD: ", textdwn))
    Dependencia.Colspan = 1
    Dependencia.HorizontalAlignment = 1
    Dependencia.BorderWidth = 0
    Ttitulo.AddCell(Dependencia)

    Dim DependenciaV As New PdfPCell(New Phrase(" INSTITUTO TECNOLOGICO SUPERIOR DE CIUDAD HIDALGO", textdwn))
    DependenciaV.Colspan = 1
    DependenciaV.HorizontalAlignment = 1
    DependenciaV.BorderWidth = 1
    Ttitulo.AddCell(DependenciaV)
    Ttitulo.AddCell(espacio)
    Ttitulo.AddCell(espacio)
    Ttitulo.AddCell(espacio)

    Dim espacioF As New PdfPCell(New Phrase(" ", salto))
    espacioF.Colspan = 1
    espacioF.BorderWidth = 0

    Ttitulo.AddCell(espacioF)
    Ttitulo.AddCell(espacioF)
    Ttitulo.AddCell(espacioF)
    Ttitulo.AddCell(espacioF)
    Dim Tfecha As New PdfPTable(3) 'tabla  para la fecha
    Dim Dia As New PdfPCell(New Phrase("DÍA", saltoF))
    Dia.Colspan = 1
    Dia.HorizontalAlignment = Element.ALIGN_CENTER
    Dia.BorderWidth = 1
    Dia.BackgroundColor = BaseColor.GRAY
    Tfecha.AddCell(Dia)
    Dim Mes As New PdfPCell(New Phrase("MES", saltoF))
    Mes.Colspan = 1
    Mes.HorizontalAlignment = Element.ALIGN_CENTER
    Mes.BorderWidth = 1
    Mes.BackgroundColor = BaseColor.GRAY
    Tfecha.AddCell(Mes)
    Dim year As New PdfPCell(New Phrase("AÑO", saltoF))
    year.Colspan = 1
    year.HorizontalAlignment = Element.ALIGN_CENTER
    year.BorderWidth = 1
    year.BackgroundColor = BaseColor.GRAY
    Tfecha.AddCell(year)

    Dim casteo As New PdfPCell((Tfecha))
    casteo.Colspan = 1
    casteo.BorderWidth = 0

    Ttitulo.AddCell(casteo)
    Ttitulo.AddCell(espacioF)


    Ttitulo.AddCell(espacio)
    Dim AreaAdmin As New PdfPCell(New Phrase("ÁREA ADMINISTRATIVA: ", textdwn))
    AreaAdmin.Colspan = 1
    AreaAdmin.HorizontalAlignment = 1
    AreaAdmin.BorderWidth = 0
    Ttitulo.AddCell(AreaAdmin)

    Dim AreaAdminv As New PdfPCell(New Phrase(" DIVISION DE SISTEMAS", textdwn))
    AreaAdminv.Colspan = 1
    AreaAdminv.HorizontalAlignment = 1
    AreaAdminv.BorderWidth = 1
    Ttitulo.AddCell(AreaAdminv)
    Ttitulo.AddCell(espacio)



    Dim TfechaV As New PdfPTable(3) 'tabla  para la fecha
    Dim DiaV As New PdfPCell(New Phrase(DateTime.Now.Day, textdwn))
    DiaV.Colspan = 1
    DiaV.HorizontalAlignment = Element.ALIGN_CENTER
    DiaV.BorderWidth = 1
    DiaV.BackgroundColor = BaseColor.WHITE
    TfechaV.AddCell(DiaV)
    Dim MesV As New PdfPCell(New Phrase(DateTime.Now.Month, textdwn))
    MesV.Colspan = 1
    MesV.HorizontalAlignment = Element.ALIGN_CENTER
    MesV.BorderWidth = 1
    MesV.BackgroundColor = BaseColor.WHITE
    TfechaV.AddCell(MesV)
    Dim yearV As New PdfPCell(New Phrase(DateTime.Now.Year, textdwn))
    yearV.Colspan = 1
    yearV.HorizontalAlignment = Element.ALIGN_CENTER
    yearV.BorderWidth = 1
    yearV.BackgroundColor = BaseColor.WHITE
    TfechaV.AddCell(yearV)

    Dim casteoV As New PdfPCell((TfechaV))
    casteo.Colspan = 1
    casteo.BorderWidth = 0

    Ttitulo.AddCell(casteoV)
    Ttitulo.AddCell(espacio)

    Ttitulo.AddCell(saltoL)

    docume.Add(Tcabecera)
    docume.Add(Ttitulo)
End Sub

Public Overrides Sub OnEndPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal archivo As iTextSharp.text.Document)
    Dim Tpie As New PdfPTable(7) 'tabla para el pie de pagina
    Dim textdwn As Font = FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD)
    Dim fntBoldRoja As Font = FontFactory.GetFont(FontFactory.TIMES, 9, Font.BOLD, New BaseColor(250, 0, 0))


    Dim espacio As New PdfPCell(New Phrase(" "))
    espacio.Colspan = 1
    espacio.BorderWidth = 0

    Tpie.AddCell(espacio)
    Tpie.AddCell(espacio)
    Tpie.AddCell(espacio)
    Tpie.AddCell(espacio)
    Tpie.AddCell(espacio)
    Tpie.AddCell(espacio)
    Tpie.AddCell(espacio)

    Tpie.WidthPercentage = 100
    Dim anchoPie() As Single = {1, 22, 22, 22, 22, 10, 1}
    Tpie.SetWidths(anchoPie)

    Tpie.AddCell(espacio)
    Dim nota As New PdfPCell(New Phrase("NOTA: EL RESGUARDANTE ES RESPONSABLE DEL BIEN Y DEL BUEN USO DE ÉSTE, Y EN CASO DE ROBO, DAÑO O PÉRDIDA DEBERÁ REPONER DICHO BIEN POR UNO IGUAL O DE MEJOR CALIDAD." & vbCrLf & "LOS BIENES DESCRITOS EN EL RESGUARDO SEGUIRÁNSIENDO DE LA RESPONSABILIDAD DEL QUE RECIBE, AÚN Y CUANDO LOS BIENES ENCONTRARAN BAJO LA CUSTODIA DE OTRA PERSONA.", fntBoldRoja))
    nota.Colspan = 5
    nota.BorderWidth = 1
    nota.HorizontalAlignment = Element.ALIGN_JUSTIFIED
    nota.VerticalAlignment = Element.ALIGN_MIDDLE
    Tpie.AddCell(nota)
    Tpie.AddCell(espacio)

    Tpie.AddCell(espacio)



    Dim resg As New PdfPCell(New Phrase("RESGUARDANTE", textdwn))
    resg.Colspan = 1
    resg.BorderWidth = 1
    resg.HorizontalAlignment = Element.ALIGN_CENTER
    resg.VerticalAlignment = Element.ALIGN_MIDDLE
    resg.BackgroundColor = BaseColor.GRAY
    Tpie.AddCell(resg)


    Dim vobo As New PdfPCell(New Phrase("VO.BO", textdwn))
    vobo.Colspan = 1
    vobo.BorderWidth = 1
    vobo.HorizontalAlignment = Element.ALIGN_CENTER
    vobo.VerticalAlignment = Element.ALIGN_MIDDLE
    vobo.BackgroundColor = BaseColor.GRAY
    Tpie.AddCell(vobo)


    Dim revisa As New PdfPCell(New Phrase("REVISA", textdwn))
    revisa.Colspan = 1
    revisa.BorderWidth = 1
    revisa.HorizontalAlignment = Element.ALIGN_CENTER
    revisa.VerticalAlignment = Element.ALIGN_MIDDLE
    revisa.BackgroundColor = BaseColor.GRAY
    Tpie.AddCell(revisa)

    Dim autoriza As New PdfPCell(New Phrase("AUTORIZA", textdwn))
    autoriza.Colspan = 1
    autoriza.BorderWidth = 1
    autoriza.HorizontalAlignment = Element.ALIGN_CENTER
    autoriza.VerticalAlignment = Element.ALIGN_MIDDLE
    autoriza.BackgroundColor = BaseColor.GRAY
    Tpie.AddCell(autoriza)


    Dim hoja As New PdfPCell(New Phrase("HOJA", textdwn))
    hoja.Colspan = 1
    hoja.BorderWidth = 1
    hoja.HorizontalAlignment = Element.ALIGN_CENTER
    hoja.VerticalAlignment = Element.ALIGN_MIDDLE
    hoja.BackgroundColor = BaseColor.GRAY
    Tpie.AddCell(hoja)
    Tpie.AddCell(espacio)


    archivo.Add(Tpie) <----- aqui me marca el error
End Sub
End Class
    
asked by antonio garcia ramos 09.10.2016 в 23:49
source

0 answers