The code is
Dim iNumMaxRegistros As Integer = 5000
' Primero obtenemos el data set
Dim sSqlString As String = "Select [nombreRecurrente],[apell1Recurrente],[apell2Recurrente],[mailRecurrente],[telefonoRecurrente],[entidad],[nifcif],[fechaTraslado],[fechaAlegacion],[idMateria],[fechaPresentado],[fechaReitInf],[fechaPeticInf2],[fechaRecepInf2],[cuantiaInicialEuros],[cuantiaFinalEuros],[cuantiaTribunalEuros],[idPonente],[fechaEntregaPonente],[fechaDevolucPonente] from Recursos where nombreRecurrente like 'J%' "
Dim dtResultados As DataSet = GetBaseDatos(sSqlString)
Dim bEsLaPrimera = True
Me.lblMensaje.Visible = False
If dtResultados.Tables(0).Rows.Count > iNumMaxRegistros Then
Me.lblMensaje.Text = "Se han encontrado " & dtResultados.Tables(0).Rows.Count & " registros. Se ha sobrepasado el límite máximo."
Me.lblMensaje.Visible = True
Else
' Dim dataSet As DataSet = GetBaseDatos("Select TOP 4000 * from Recursos")
' Obtenemos la lista de centros directivos
'Create PDF document
Dim doc As PdfDocument = New PdfDocument()
'Set page orientation
' doc.PageSettings.Orientation = PdfPageOrientation.Portrait
doc.PageSettings.Orientation = PdfPageOrientation.Landscape
Dim page As PdfPage = doc.Pages.Add()
Dim resul As PdfLayoutResult = Nothing
Dim point As Drawing.PointF = New Drawing.PointF(0, 0)
'Adding Header
Me.AddHeader(doc, "Tabla Recursos", "")
Dim dtCentrosDirectivos As DataSet = GetBaseDatos("select distinct (Recursos.idCentro),centros_directivos.nombre from Recursos,centros_directivos where Recursos.idCentro= centros_directivos.idCentro order by idCentro")
For Each dtRow As DataRow In dtCentrosDirectivos.Tables(0).Rows
Dim dtResul As DataSet
Dim sSqlStrCentro = "Select Recursos.idCentro, centros_directivos.nombre,[nombreRecurrente],[apell1Recurrente],[apell2Recurrente],[mailRecurrente]," + _
" [telefonoRecurrente],[entidad],[nifcif],[fechaTraslado],[fechaAlegacion],[idMateria]," + _
" [fechaPresentado],[fechaReitInf],[fechaPeticInf2],[fechaRecepInf2],[cuantiaInicialEuros]," + _
" [cuantiaFinalEuros],[cuantiaTribunalEuros],[idPonente],[fechaEntregaPonente]," + _
" [fechaDevolucPonente]" + _
" from Recursos, centros_directivos " + _
" where Recursos.idCentro = centros_directivos.idCentro and Recursos.idCentro=" + dtRow.Item(0).ToString + _
" and nombreRecurrente like 'J%'" + _
" order by Recursos.idCentro"
dtResul = GetBaseDatos(sSqlStrCentro)
If dtResul.Tables(0).Rows.Count > 0 Then
' la pintamos
'Use DataTable as source
Dim table As PdfLightTable = New PdfLightTable()
table = CrearTabla(doc, dtResul)
'Set layout properties
Dim format As PdfLayoutFormat = New PdfLayoutFormat()
format.Break = PdfLayoutBreakType.FitElement
format.Layout = PdfLayoutType.Paginate
'Draw table
If bEsLaPrimera Then
point = New Drawing.PointF(0, 0)
resul = table.Draw(page, point)
bEsLaPrimera = False
Else
'If Not bHayEspacio(resul) Then
' page = doc.Pages.Add()
' point = New Drawing.PointF(0, 0)
'End If
Dim font As Syncfusion.Pdf.Graphics.PdfStandardFont = New Syncfusion.Pdf.Graphics.PdfStandardFont(PdfFontFamily.Helvetica, 12.0F, PdfFontStyle.Bold)
''Draw text in the new page.
Dim texto = New PdfTextElement("Esta es otra tabla", font)
point = New Drawing.PointF(resul.Bounds.Left, resul.Bounds.Bottom + 20) 'cogemos la última posicion
resul = texto.Draw(doc.Pages.Item(doc.Pages.Count - 1), point)
' escribimos la siguiente
point = New Drawing.PointF(resul.Bounds.Left, resul.Bounds.Bottom + 20) 'cogemos la última posicion
'If Not bHayEspacio(resul) Then
' page = doc.Pages.Add()
' point.Y = 0
'End If
resul = table.Draw(doc.Pages.Item(doc.Pages.Count - 1), point)
End If
End If
Next
'Save to disk
'Stream the output to the browser.
If Me.CheckBox1.Checked Then
doc.Save("Sample.pdf", Response, HttpReadType.Open)
Else
doc.Save("Sample.pdf", Response, HttpReadType.Save)
End If
End If
El código que crea la tabla es
Private Function CrearTabla(ByVal doc As PdfDocument, ByVal dtResultados As DataSet) As PdfLightTable
'Set font
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 8)
'Create Pdf ben for drawing broder
Dim borderPen As PdfPen = New PdfPen(PdfBrushes.DarkBlue)
borderPen.Width = 0
'Create brush
Dim color As PdfColor = New PdfColor(192, 201, 219)
Dim brush As PdfSolidBrush = New PdfSolidBrush(color)
'Create cell styles
Dim altStyle As PdfCellStyle = New PdfCellStyle()
altStyle.Font = font
altStyle.BackgroundBrush = brush
altStyle.BorderPen = borderPen
Dim defStyle As PdfCellStyle = New PdfCellStyle()
defStyle.Font = font
defStyle.BackgroundBrush = PdfBrushes.White
defStyle.BorderPen = borderPen
Dim headerStyle As PdfCellStyle = New PdfCellStyle(font, PdfBrushes.White, PdfPens.DarkBlue)
brush = New PdfSolidBrush(System.Drawing.Color.FromArgb(33, 67, 126))
headerStyle.BackgroundBrush = brush
'Use DataTable as source
Dim table As PdfLightTable = New PdfLightTable()
'Create datatable
Dim dataTable As DataTable = dtResultados.Tables(0)
'Set Data source
table.DataSource = dataTable
'Set table alternate row style
table.Style.AlternateStyle = altStyle
'Set default style
table.Style.DefaultStyle = defStyle
'Set header row style
table.Style.HeaderStyle = headerStyle
'Show the header row
table.Style.ShowHeader = True
'Repeate header in all the pages
table.Style.RepeatHeader = True
'Set header data from column caption
table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions
table.Style.BorderPen = borderPen
table.Style.BorderPen = borderPen
table.Style.CellPadding = 2
table.Columns(1).Width = 12
table.Style.HeaderStyle.StringFormat = New PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle)
table.Style.DefaultStyle.StringFormat = New PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle)
Return table
End Function
TableAgrupadaToPDF.aspx_fa3fac0.rar