We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Error when adding tables to a pdf

Thread ID:





91683 Nov 27,2009 12:10 PM UTC Sep 22,2014 12:05 PM UTC ASP.NET Web Forms (Classic) 7
Tags: PDF
Jose Antonio
Asked On November 27, 2009 12:10 PM UTC

I am creating a pdf and adding a number of different pdf tables

Private Function CrearTabla(ByVal doc As PdfDocument, ByVal dtResultados As DataSet) As PdfLightTable

The problem is that I have to group the results of a table by Center:

Center: Center1
Table of Center1

Center: Center2
Table of Center2

One idea is to make different selects and write one by one but
when I add the number 12 arises an error:

Syncfusion.Pdf.Tables.PdfLightTableException was unhandled by user code
Message="Can't draw table, because there is not enough space for it."
en Syncfusion.Pdf.Tables.LightTableLayouter.LayoutOnPage(Int32 startRowIndex, PdfLayoutParams param, Boolean isPageFirst)
en Syncfusion.Pdf.Tables.LightTableLayouter.LayoutInternal(PdfLayoutParams param)
en Syncfusion.Pdf.Graphics.ElementLayouter.Layout(PdfLayoutParams param)
en Syncfusion.Pdf.Tables.PdfLightTable.Layout(PdfLayoutParams param)
en Syncfusion.Pdf.Graphics.PdfLayoutElement.Draw(PdfPage page, RectangleF layoutRectangle, PdfLayoutFormat format)
en Syncfusion.Pdf.Graphics.PdfLayoutElement.Draw(PdfPage page, Single x, Single y, PdfLayoutFormat format)
en Syncfusion.Pdf.Graphics.PdfLayoutElement.Draw(PdfPage page, Single x, Single y)
en Syncfusion.Pdf.Graphics.PdfLayoutElement.Draw(PdfPage page, PointF location)
en Syncfusion.Pdf.Tables.PdfLightTable.Draw(PdfPage page, PointF location)
en TestSyncFusion.TableAgrupadaToPDF.Button1_Click(Object sender, EventArgs e) en C:\Documents and Settings\jamacia\Mis documentos\Biblioteca SyncFusion\TestSyncFusion\TestSyncFusion\TableAgrupadaToPDF.aspx.vb:línea 109
en System.Web.UI.WebControls.Button.OnClick(EventArgs e)
en System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
en System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
en System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
en System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
en System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

But when I get all the results of query of all results, there's no error.

Why is the error ? How I can do that in other way ?

Thanks in advance

Meiyappan R [Syncfusion]
Replied On November 30, 2009 04:27 AM UTC

Thanks for your interest in Essential Pdf.
Sorry for the delay.We are looking into your issue.Could you send the code sample you used so that it will be useful for us to view deeply into the problem.


Jose Antonio
Replied On November 30, 2009 09:37 AM UTC

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
' 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
'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


'Save to disk
'Stream the output to the browser.
If Me.CheckBox1.Checked Then
doc.Save("Sample.pdf", Response, HttpReadType.Open)
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


Meiyappan R [Syncfusion]
Replied On December 4, 2009 11:17 AM UTC

Hi Jose
We regret for the delay caused in getting back to you.
We were able to reproduce the issue and you can look into the below link for writing a table continuously in a pdf we have.We implemented it using grid.



Jose Antonio
Replied On December 4, 2009 12:48 PM UTC

Thank you very much !!! It works perfectly !!

Jose Antonio
Replied On December 30, 2009 12:24 PM UTC

Sorry if I disturb you, the solution you gave of adding several tables works well but I would like to write text (a line) before each table (a line) and I don't know how to do it. ¿ Can you help me ?


Meiyappan R [Syncfusion]
Replied On January 4, 2010 01:28 PM UTC

Hi jose,
Please look into the sample attached to the below link.


Kindly let us know whether it helps.


David Seipp
Replied On September 22, 2014 12:05 PM UTC

The link specified doesn't seem to be working as the website is throwing an error.  can you post the relevant code to get this working?  I'm also having issues with page boundaries and table.Draw(...)



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon