"System.StackOverflowException" in "OnEndPage" event handler

In the code below, you can see that I have overridden the event OnEndPage

and tried to add a paragraph to the document. However, trying to run the code throws a "System.StackOverflowException" error. Does anyone know why this is happening and how I can fix it?

public override void OnEndPage(PdfWriter writer, Document document)
{
    base.OnEndPage(writer, document);
    Paragraph p = new Paragraph("Paragraph");
    document.Add(p);
}

      

0


source to share


1 answer


forbidden to use document.Add()

in page event. The object document

passed as a parameter is actually an object PdfDocument

. You should use it read-only. This is covered in my book iText in Action - Second Edition .



If you want to add content to a method OnEndPage

, you will need writer

eg writer.DirectContent

.

+2


source







All Articles