VahidN / PdfReport.Core

PdfReport.Core is a code first reporting engine, which is built on top of the iTextSharp.LGPLv2.Core and EPPlus.Core libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

custom header with Fill AcroForm

1001co opened this issue · comments

i want to customize header with fill pdf Template and then convert to image with PdfImageHelper.GetITextSharpImageFromAcroForm() method to set header.

    public class CustomHeader : IPageHeader
    {
        public PdfGrid RenderingGroupHeader(Document pdfDoc, PdfWriter pdfWriter, IList<CellData> rowdata, IList<SummaryCellData> summaryData)
        {
            return null; // don't render anything.
        }

        iTextSharp.text.Image _image;
        public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList<SummaryCellData> summaryData)
        {
            if (_image == null) //cache is empty
            {
                _image = PdfImageHelper.GetITextSharpImageFromAcroForm(pdfWriter, _templatePath, null, onFillAcroForm: (data, form, pdfStamper) =>
                  {
                      form.GenerateAppearances = true;

                      form.SetField("Date", "1401/01/29");
                      form.SetField("Code", "00/4756");

                  }, null);
            }


            var table = new PdfGrid(1);
            var cell = new PdfPCell(_image, true) { Border = 0 };
            table.AddCell(cell);
            return table;

            //Note: return null if you want to skip this callback and render nothing. Also in this case, you need to set the header.CacheHeader(cache: false) too.
        }
    }

How to initial cellData and font for onFillAcroForm in custom header.

It's better to use itextsharp directly for your scenario.