custom header with Fill AcroForm
1001co opened this issue · comments
1001co commented
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.
Vahid Nasiri commented
It's better to use itextsharp directly for your scenario.