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. Image for the cookie policy date
close icon

Error when adding tables to a pdf

Hi
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."
Source="Syncfusion.Pdf.Base"
StackTrace:
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


7 Replies

MR Meiyappan R Syncfusion Team November 30, 2009 04:27 AM UTC

Hi
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.

Thanks
Meiyappan.R


JA Jose Antonio 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
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


MR Meiyappan R Syncfusion Team 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.

http://files.syncfusion.com/samples/PDF.Web/sampletest.zip

Regards
Meiyappan




JA Jose Antonio December 4, 2009 12:48 PM UTC

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


JA Jose Antonio 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 ?

Thanks


MR Meiyappan R Syncfusion Team January 4, 2010 01:28 PM UTC

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

http://help.syncfusion.com/samples/pdf/sampletest.zip

Kindly let us know whether it helps.

Regards
Meiyappan


DS David Seipp 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(...)

thanks!

Loader.
Live Chat Icon For mobile
Up arrow icon