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

How to create a simple table with explicit columns

I've only been using the PDF tool for a day now, but am frustrated by the samples.

I can create a simple table using the "Northwind Customers" sample, but can't figure out how to customize the column headings or to exclude certain columns.

Are there any sample that show how to create a "customized" table?

thanks,
bert

7 Replies

PJ Pravin Joshua D Syncfusion Team February 3, 2010 06:10 AM UTC

Hi Bert,

Thank you for using Syncfusion Products.

Please refer the following sample to create customized table.Also, refer to the online sample and documentation, to know more about the feature PDF Light Table.

Sample:

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

Online Sample:
http://samples.syncfusion.com/ASPNET/8.1.0.26/web/Pdf.Web/samples/3.5/Tables/TableFeatures/CS/Default.aspx?args=4

Documentation Link:
http://help.syncfusion.com/ug_81/Reporting_PDF/default.html
(Please open Index--> Customizing Tables in the above link)

Please try this and let us know if you have any questions.

Regards,
Pravin Joshua D


BS Bert Sirkin February 3, 2010 01:34 PM UTC

Thanks for the links - but I'm trying to create the table manually - one row at a time.

I've figured out how to code a table with manual row/column data. At some point I had it working, but can't get it to work again. I need to make a "purchase" recommendation, but need to be able to show a sample report (with real data).

Here's my "hello world" table app. Can you please let me know what I'm doing wrong? The string with the date shows up in the PDF, but the table shows up as a single thin solid line right below the date. When I query the table object from the code, I can see there are 2 columns and 100 rows, but nothing shows up.

thanks,
bert

*********************************************
Option Explicit On
Option Strict On

Imports System.Drawing
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Tables

Partial Public Class test
Inherits System.Web.UI.Page


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'====================================================================================
' definitions
'====================================================================================
' pen
Dim borderPen As PdfPen = New PdfPen(PdfBrushes.DarkBlue)
borderPen.Width = 0
'-----------------
' default style
Dim defStyle As PdfCellStyle = New PdfCellStyle()
defStyle.Font = New PdfStandardFont(PdfFontFamily.Helvetica, 8, PdfFontStyle.Regular)
defStyle.BackgroundBrush = PdfBrushes.White
defStyle.BorderPen = borderPen
'-----------------


Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPage = doc.Pages.Add()
Dim tblPDF As PdfLightTable = New PdfLightTable()
' AddHeader(doc, "Sample Report", "")

' table properties
tblPDF.Style.BorderPen = borderPen
tblPDF.Style.BorderPen = borderPen
tblPDF.Style.CellPadding = 2

'===================================
' Create 2 Columns
Dim colPDF As PdfColumn
colPDF = New PdfColumn
colPDF.ColumnName = "Left Aligned Column"
colPDF.Width = 100
colPDF.StringFormat = New PdfStringFormat(PdfTextAlignment.Left)
tblPDF.Columns.Add(colPDF)

colPDF = New PdfColumn
colPDF.ColumnName = "Right Aligned Column"
colPDF.Width = 50
colPDF.StringFormat = New PdfStringFormat(PdfTextAlignment.Right)
tblPDF.Columns.Add(colPDF)
'===================================


'===================================
' add some text
Dim g As PdfGraphics = page.Graphics
g.DrawString("Today's date is: " & Now.ToLongDateString, _
New PdfStandardFont(PdfFontFamily.Helvetica, 8, PdfFontStyle.Bold), _
New PdfSolidBrush(New PdfColor(System.Drawing.Color.Black)), _
5, _
8)
'===================================


'===================================
' Adding Rows
For iCount1 As Integer = 1 To 100
tblPDF.Rows.Add(New Object() {"test " & iCount1.ToString, _
iCount1.ToString})
Next
'===================================


' Draw the table
Dim f As New System.Drawing.PointF(20, 20)
tblPDF.Draw(page.Graphics, New PointF(20, 20), 600)

doc.Save("Sample.pdf", Response, HttpReadType.Open)
End Sub


End Class






PJ Pravin Joshua D Syncfusion Team February 4, 2010 04:04 AM UTC

Hi Bert,

In order to apply the datasource for the PDFLightTable directly, the following code snippet should be added :

table.DataSourceType = PdfLightTableDataSourceType.TableDirect;

We have also modified your sample and now the PDF Light Table is generated .
Please have look at the attached sample.

Sample:

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

Please try this and let us know if you have any questions.

Regards,
Pravin Joshua D


BS Bert Sirkin February 4, 2010 12:43 PM UTC

Thanks!

One last question (I hope!):

I changed the code to extract data from our database and added a page header and column headings. I have 3 columns and the first is left-aligned and the other two are right-aligned. The DATA in the later 2 columns are correctly aligned (right), but ALL of the column headings are LEFT aligned. I'm creating my column headings as follows:

---------------------------------------
Dim colPDF As PdfColumn
colPDF = New PdfColumn
colPDF.ColumnName = "Revision"
colPDF.Width = 70
colPDF.StringFormat = New PdfStringFormat(PdfTextAlignment.Left)
tblPDF.Columns.Add(colPDF)

colPDF = New PdfColumn
colPDF.ColumnName = "Hours"
colPDF.Width = 25
colPDF.StringFormat = New PdfStringFormat(PdfTextAlignment.Right)
tblPDF.Columns.Add(colPDF)

colPDF = New PdfColumn
colPDF.ColumnName = "Cost"
colPDF.Width = 25
colPDF.StringFormat = New PdfStringFormat(PdfTextAlignment.Right)
tblPDF.Columns.Add(colPDF)
---------------------------------------

and I set the following properties on the table:

---------------------------------------
tblPDF.Style.AlternateStyle = altStyle
tblPDF.Style.DefaultStyle = defStyle
tblPDF.Style.HeaderStyle = headerStyle
tblPDF.Style.ShowHeader = True
tblPDF.Style.RepeatHeader = True
tblPDF.Style.HeaderSource = PdfHeaderSource.ColumnCaptions
---------------------------------------

Why aren't the column headings 2 & 3 aligning right?

thanks,
bert


MR Meiyappan R Syncfusion Team February 8, 2010 03:10 PM UTC

Hi Bert,

We can modify the cell alignment through the layout handlers.

Could you please download the sample explaining the same from the below location.

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

Kindly let us know if this works.

Regards
Meiyappan


AS Anita Sheffield September 15, 2015 08:47 PM UTC

I am trying to create custom columns for xamarin.forms PdfLightTable, but the links here are not valid. Does someone have an example of this?
Using an IEnumerable for the datasource, I need to be able to dynamically select columns to be included in the table.


PH Praveenkumar H Syncfusion Team September 18, 2015 07:38 AM UTC

Hi Anita,

Thank you for using syncfusion products,

We have created the simple sample to create a PdfLightTable from IEnumerable datasource.

Please find the sample from the below link.
http://www.syncfusion.com/downloads/support/forum/92687/ze/PdfTableCreation186275767.zip

With Regards,
Praveen

Loader.
Live Chat Icon For mobile
Up arrow icon