title: Is it possible to add a footnote depending on the page contents when using itext?
body: <p>I am using Itext 5.5 and right now, I have a custom implementation of <code>PdfPageEventHelper</code> that adds a footer to the page containing Page number information.</p>
  
  <p>Recent changes in my application lead to the existence of necessary footnotes. The way I am creating the PDF (dynamically created from a list of Components) makes it effectively impossible to determine which page contains which items, as that is part of customizable Styling options.</p>
  
  <p>However, I need to add explanations to the footnote markers.
  The approach I have now is to simply notify the <code>PdfPageEventHelper</code> that, somewhere in the document, there is at least one element that needs the (currently only) footnote, and then I add the explanatory footnote to <em>every</em> Page.</p>
  
  <p>This is something I want to avoid, as the future might bring more footnotes and explanations.
  So the question is:</p>
  
  <p>Can I parse the current page content directly and scan for the existence of marker text? Or is there another way to see if the current page needs the explanatory footnote?</p>
  
  <p>My failed approaches so far (all in <code>onEndPage(PdfWriter, Document)</code>):</p>
  
  <pre><code>PdfContentByte cb = writer.getDirectContent();
  PdfReader reader = new PdfReader(cb.toPdf(writer());
  // this led to InvalidPdfException
  ----
  ColumnText ct = new ColumnText(cb);
  ct.getCompositeElements();
  // returned null, I expected the current page contents
  ----
  OutputStreamCounter oc = writer.getOs();
  // did not expose any useful methods. also, cannot read from OutputStream
  </code></pre>
  
  <p>Googling the problem yielded dozens of results - how to add a page number or how to add a document-static, user-specific header. But nothing page-depending.</p>
  
  <p>Oh, and this, which is not really helpful:
  <a href="https://stackoverflow.com/questions/41383651/adding-a-pdf-footer-conditionally-on-certain-pages-in-a-multi-page-pdf-document">Adding a pdf footer conditionally on certain pages in a multi-page pdf document</a></p>
  
  <p>which seems basically to be the exact same problem as mine.</p>