Spire.DataExport : Style PDF Header

Technical support for Spire.DataExport

Moderators: iceblue support, DataExport, Manager

Spire.DataExport : Style PDF Header

Postby gargmanoj@gmail.com » Sat Oct 19, 2013 2:42 pm

Hi,

Is it possible to style header row in the PDF file when a datatable is exported Just like we can do in XLS file? I want to have a background color and custom font color in the table header in PDF?

Thanks in advance
gargmanoj@gmail.com
 
Posts: 7
Joined: Tue May 15, 2012 2:52 pm

Re: Spire.DataExport : Style PDF Header

Postby Gary.zhang » Mon Oct 21, 2013 6:55 am

Hi,
Thanks for your inquiry.
Regarding your needs, you could refer to the following code,
Code: Select all
PdfDocument doc = new PdfDocument();
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Bottom = margin.Top;
margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Right = margin.Left;
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
float y = 10;
PdfTable table = new PdfTable();
table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.LightBlue;
table.Style.ShowHeader = true;
using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select Name,Capital,Continent,Area,Population from country ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
PdfLayoutResult result = table.Draw(page, new PointF(0, y));
doc.SaveToFile("SimpleTable.pdf");

If there are any questions, welcome to get it back to us.
Regards,
Gary
E-iceblue support team
User avatar
Gary.zhang
 
Posts: 1362
Joined: Thu Apr 04, 2013 1:30 am

Re: Spire.DataExport : Style PDF Header

Postby gargmanoj@gmail.com » Mon Oct 21, 2013 12:25 pm

Hi Gary,

I could not file classes PdfDocument, PdfTable in the Spire.DataExport dll. I am using the 3.2.7.4 version of Spire.DataExport.dll

Can you please help me out with this
gargmanoj@gmail.com
 
Posts: 7
Joined: Tue May 15, 2012 2:52 pm

Re: Spire.DataExport : Style PDF Header

Postby amy.zhao » Tue Oct 22, 2013 8:36 am

Hi,

Sorry that the previous code was provided using our Spire.PDF component. We provide you the following solution using our Spire.DataExport now, but Spire.DataExport doesn't support to set background color at present and the below solution just show you how to set custom font color. Sorry for the inconvenience. But you could use our Spire.PDF component to implement all your need. Welcome to test the previous code using Spire.PDF. Please feel free to write to us again in case you have further questions.

Code: Select all
DataTable dataTable;
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select Name,Capital,Continent,Area,Population from country ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                }
            }

            Spire.DataExport.HTML.HTMLExport HTMLExport = new Spire.DataExport.HTML.HTMLExport();

            Spire.DataExport.PDF.PDFExport PDFExport = new Spire.DataExport.PDF.PDFExport();
            PDFExport.PDFOptions.TitleFont.Color = Color.Red;
            PDFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            PDFExport.DataTable = dataTable;

            PDFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;

            PDFExport.SaveToFile("20110223.pdf");




Best regards,
Amy
E-iceblue support team
User avatar
amy.zhao
 
Posts: 2202
Joined: Wed Jun 27, 2012 8:50 am

Re: Spire.DataExport : Style PDF Header

Postby amy.zhao » Fri Oct 25, 2013 2:51 am

Hi,

If you would evaluate Spire.PDF, please kindly download it from the link
http://www.e-iceblue.com/Download/downl ... t-now.html.

Please refer to more demos of PDF table from the following link.
http://www.e-iceblue.com/Knowledgebase/ ... Table.html

Welcome to write to us if you have any problems.

Best regards,
Amy
E-iceblue support team
User avatar
amy.zhao
 
Posts: 2202
Joined: Wed Jun 27, 2012 8:50 am


Return to Spire.DataExport

Who is online

Users browsing this forum: No registered users and 0 guests

cron