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

CustomHeader

Feb 27, 2013 at 12:45 PM
Edited Feb 27, 2013 at 12:46 PM
Looking for a good example for a Custom Header. Most of my reports have a lot of details above the columns. (like an invoice)

I have followed a similar example where:
    header.CustomHeader(new MasterDetailsHeaders {PdfRptFont = header.PdfFont });
and then
   public class MasterDetailsHeaders : IPageHeader
    {
        public IPdfFont PdfRptFont { set; get; }
     }

      public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList<SummaryCellData> summaryData) 
      {  
      return table
       }
 
How do pass the summary table (ie Header data)?

looking for Like:
header.CustomHeaderIList=MyHeaderData;

Thanks,
Mike
Coordinator
Feb 27, 2013 at 1:54 PM
There are 3 ways to create a custom header:
Using the inline headers is a preferred way. In this case passing data or defining custom shapes is much easier:
 .PagesHeader(header =>
            {
                header.InlineHeader(inlineHeader =>
                {
                    inlineHeader.AddPageHeader(data =>
                    {
                        return createHeader(header);
                    });
                });
            })
//...
private static PdfGrid createHeader(PagesHeaderBuilder header)
        {
            var table = new PdfGrid(numColumns: 1)
            {
                WidthPercentage = 100,
                RunDirection = PdfWriter.RUN_DIRECTION_LTR,
                SpacingAfter = 7
            };

            var title = header.PdfFont.FontSelector.Process("Our new rpt.");
            var pdfCell = new PdfPCell(title)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft = 0,
                BorderWidthRight = 0,
                BorderWidthTop = 0,
                BorderWidthBottom = 1,
                Padding = 4,
                BorderColorBottom = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_CENTER
            };

            table.AddCell(pdfCell);
            return table;
        }
+
Defining custom headers need some background about creating tables with iTextSharp (PdfGrid here is a sub class of PdfPTable).
Here you can find a good starting point: http://www.mikesdotnetting.com/Category/20
Feb 27, 2013 at 3:47 PM
Thanks!

Your example CustomHeaderFooter still doesn't show passing summary data in the initial lamda?

If I was going to print an invoice, I would start with a table of Items purchased,qty and Prices that would be considered "MainTable" and Header data like Invoice Number and Date, Customer Name and Address... which Looks like the RenderingGroupHeader wants as an IList called summaryData. Where is SummaryData Set?

Thanks Again,
Mike
Feb 27, 2013 at 4:04 PM
Ok, I figured it out, Just need to declare it public and pass it - duh. Some time I forget how powerful lambda's are
             .PagesHeader(header => 
             {
                 header.CustomHeader(new MasterDetailsHeaders {
                     HeaderData = InvoiceHeaderData,
                     PdfRptFont = header.PdfFont });
             })

     public class MasterDetailsHeaders : IPageHeader
    {
        public IPdfFont PdfRptFont { set; get; }
        public IList<headerdata> HeaderData { set; get; }

      public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList<SummaryCellData> summaryData) 
      {  
      }