Add Footnotes and Endnotes in PDF using Java.

A footnote is a note or text given at the bottom of a specific page, whereas the endnote is placed at the end of a document. We usually use footnotes or endnotes for references, explanations, or comments. You can add footnotes/endnotes to a PDF programmatically. In this article, we will learn how to add footnotes and endnotes in PDF documents using Java.

The following topics are covered:

Java API to Add Footnotes and Endnotes in PDF

For adding footnotes and endnotes to a PDF document, we will use Aspose.PDF for Java API. It lets you generate, modify, convert, render, secure, and print supported documents without Adobe Acrobat. Download the JAR from the link below or add the following pom.xml configuration to a Maven‑based Java project.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>22.1</version>
</dependency>

Add Footnotes to a PDF using Java

Follow these steps to add footnotes at the bottom of a page:

  1. Create an instance of the Document class.
  2. Add a Page to the PagesCollection.
  3. Create a TextFragment.
  4. Set the Footnote value for the TextFragment.
  5. Add the TextFragment to the Paragraphs collection.
  6. Repeat steps 3‑5 for additional footnotes if needed.
  7. Save the PDF with Document.Save(), providing the output path.

The code sample below demonstrates how to add footnotes to a PDF document using Java.

Add Footnotes to a PDF using Java.

Add Footnotes to a PDF using Java.

Add an Image to Footnote in PDF

To embed an image inside a footnote:

  1. Create a Document instance.
  2. Add a Page to the PagesCollection.
  3. Create a TextFragment.
  4. Set its Footnote value.
  5. Attach an image to the TextFragment.
  6. Add the TextFragment to Paragraphs.
  7. Save the PDF with Document.Save().

The following sample shows how to add an image in the footnotes of a PDF document using Java.

Add an Image to Footnote in PDF.

Add an Image to Footnote in PDF.

Insert a Table to Footnote in PDF

To place a table inside a footnote:

  1. Create a Document instance.
  2. Add a Page to the PagesCollection.
  3. Create a TextFragment.
  4. Set its Footnote value.
  5. Add a table to the TextFragment.
  6. Add the TextFragment to Paragraphs.
  7. Save the PDF with Document.Save().

The code below illustrates how to add a table in the footnotes of a PDF document using Java.

Insert a Table to Footnote in PDF.

Insert a Table to Footnote in PDF.

Customize Footnote Label and Line Style using Java

To change the footnote label and line appearance:

  1. Create a Document instance.
  2. Add a Page to the PagesCollection.
  3. Initialize a [GraphInfo][17] object to define line style (width, color, dash pattern, etc.).
  4. Create a TextFragment.
  5. Set its Footnote value.
  6. Initialize a TextState object and set properties such as foreground color and font style.
  7. Add the TextFragment to Paragraphs.
  8. Repeat for additional footnotes if required.
  9. Save the PDF with Document.Save().

The sample demonstrates how to customize footnote labels and line styles using Java.

Customize Footnote Label and Line Style using Java.

Customize Footnote Label and Line Style using Java.

Add Footnotes to Existing PDF using Java

To insert footnotes into an existing PDF:

  1. Load the PDF with the Document class.
  2. Retrieve the target page by index.
  3. Create a [TextFragmentAbsorber][19] with the search phrase.
  4. Call the [accept()][20] method to locate the phrase.
  5. Get the first match from _[TextFragmentCollection][21].
  6. Create an empty TextFragment and position it on the page.
  7. Set its Footnote value.
  8. Add the TextFragment to Paragraphs.
  9. Save the PDF with Document.Save().

The following code shows how to add footnotes to an existing PDF document using Java.

Add-Foot-Notes-to-Existing-PDF-using-Java

Add Footnotes to Existing PDF using Java.

Add Endnotes to PDF using Java

To add endnotes at the end of a document:

  1. Create a Document instance.
  2. Add a Page to the PagesCollection.
  3. Create a TextFragment.
  4. Set the Endnote value for the TextFragment.
  5. Optionally, assign a custom label to the endnote.
  6. Add the TextFragment to Paragraphs.
  7. Save the PDF with Document.Save().

The sample below shows how to add endnotes to a PDF document using Java.

Get a Free API License

You can try the API without evaluation limitations by requesting [a free temporary license][23].

Conclusion

In this article, we have learned how to:

  • add footnotes and endnotes to a PDF document using Java;
  • embed an image or a table inside footnotes;
  • customize footnote labels and line styles;
  • insert footnotes into an existing PDF.

For more details, explore the Aspose.PDF for Java [documentation][24]. If you have questions, visit the [forum][25].

See Also

  • [Convert PDF to Word using Java][26]