I want to add a dynamic footer in itext7 using C#. The footer can vary from 1 to 6 lines of text. I have been able to implement single line footers but the long text is being truncated.
Please help.
Code to add footer:
class CustomEventHandler : IEventHandler
{
protected Document doc;
private Table table;
public CustomEventHandler(Document doc)
{
this.doc = doc;
}
public CustomEventHandler(Table table)
{
this.table = table;
}
public void HandleEvent(Event currentEvent)
{
PdfDocumentEvent docEvent = (PdfDocumentEvent)currentEvent;
Rectangle pageSize = docEvent.GetPage().GetPageSize();
PdfFont font = null;
try
{
font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_OBLIQUE);
}
catch (IOException e)
{
Console.Error.WriteLine(e.Message);
}
float coordX = pageSize.GetLeft() + doc.GetLeftMargin();
float headerY = pageSize.GetTop() - doc.GetTopMargin() + 10;
float footerY = doc.GetBottomMargin();
Canvas canvas = new Canvas(docEvent.GetPage(), pageSize);
canvas
.SetFont(font)
.SetFontSize(5)
.ShowTextAligned("this is a header", coordX, headerY, TextAlignment.CENTER)
.ShowTextAligned("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", coordX, footerY, TextAlignment.LEFT)
.Close();
}
}
Thanks Priyanka