This project has moved. For the latest updates, please go here.

There are some built-in report templates in PdfReport library such as BasicTemplate.RainyDayTemplate, BasicTemplate.SilverTemplate, etc. Also it's possible to create the new main table's templates by implementing the ITableTemplate interface. For instance:

using System.Collections.Generic;
using System.Drawing;
using iTextSharp.text;
using PdfRpt.Core.Contracts;

namespace PdfReportSamples.HexDump
{
    public class GrayTemplate : ITableTemplate
    {
        public HorizontalAlignment HeaderHorizontalAlignment
        {
            get { return HorizontalAlignment.Center; }
        }

        public BaseColor AlternatingRowBackgroundColor
        {
            get { return new BaseColor(Color.WhiteSmoke); }
        }

        public BaseColor CellBorderColor
        {
            get { return new BaseColor(Color.LightGray); }
        }

        public IList<BaseColor> HeaderBackgroundColor
        {
            get { return new List<BaseColor> { new BaseColor(ColorTranslator.FromHtml("#990000")), new BaseColor(ColorTranslator.FromHtml("#e80000")) }; }
        }

        public BaseColor RowBackgroundColor
        {
            get { return null; }
        }

        public IList<BaseColor> PreviousPageSummaryRowBackgroundColor
        {
            get { return new List<BaseColor> { new BaseColor(Color.LightSkyBlue) }; }
        }

        public IList<BaseColor> SummaryRowBackgroundColor
        {
            get { return new List<BaseColor> { new BaseColor(Color.LightSteelBlue) }; }
        }

        public IList<BaseColor> PageSummaryRowBackgroundColor
        {
            get { return new List<BaseColor> { new BaseColor(Color.Yellow) }; }
        }

        public BaseColor AlternatingRowFontColor
        {
            get { return new BaseColor(ColorTranslator.FromHtml("#333333")); }
        }

        public BaseColor HeaderFontColor
        {
            get { return new BaseColor(Color.White); }
        }

        public BaseColor RowFontColor
        {
            get { return new BaseColor(ColorTranslator.FromHtml("#333333")); }
        }

        public BaseColor PreviousPageSummaryRowFontColor
        {
            get { return new BaseColor(Color.Black); }
        }

        public BaseColor SummaryRowFontColor
        {
            get { return new BaseColor(Color.Black); }
        }

        public BaseColor PageSummaryRowFontColor
        {
            get { return new BaseColor(Color.Black); }
        }

        public bool ShowGridLines
        {
            get { return true; }
        }
    }
}

To use this new template, we can write:

.MainTableTemplate(template =>
{
      template.CustomTemplate(new GrayTemplate());
})

 

Some tips and tricks

- Colors in iTextSharp library are defined by the BaseColor class. If you want to convert the colors of System.Drawing to BaseColor, just pass it to the BaseColor's constructor:

var blackColor = new BaseColor(Color.Black);

- There are some useful helper methods in .NET classes such as ColorTranslator.FromHtml to convert and use the HTML colors.
- If you want to define a transparent color here, just return null.
- In the ITableTemplate interface some colors are defined as a list. These properties can accept one or max 2 colors. If 2 colors are specified, an automatic gradient of these colors will be shown on the report.

Last edited Nov 6, 2012 at 5:59 PM by VahidN, version 3

Comments

No comments yet.