Add an outline to a PDF
A PDF Outline (also known as bookmarks) allows users to navigate through the document, similarly to a contents page.
Adding an outline can be done programmatically. Copying an outline can be done programmatically or from the command line.
How to write an outline to a PDF file
Outlines are represented by a Document
object.
final Document outline;
final OutlineWriter outlineWriter = new OutlineWriter("inputFile.pdf", outline);
try {
outlineWriter.writeOutline();
} catch (final IOException | PdfException e) {
e.printStackTrace();
}
How to copy an outline from one PDF file to another programmatically
JPedal also allows you to extract an outline from a PDF file meaning you can write it to another one.
More information here.
How to copy an outline from one PDF file to another using the command line
JPedal has a convenient way to copy an outline between PDF files using the command line.
java -jar jpedal.jar --copyoutline "inputFile.pdf" "outputFile.pdf"