import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfOutline;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate template = cb.createTemplate(25, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
cb.addTemplate(template, 87, 87);
PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
PdfDestination d5 = new PdfDestination(PdfDestination.FIT);
PdfOutline root = cb.getRootOutline();
PdfOutline out1 = new PdfOutline(root, d1, "root", true);
PdfOutline out2 = new PdfOutline(out1, d2, "sub 1", false);
new PdfOutline(out2, d4, "sub 2.1");
new PdfOutline(out2, d5, "sub 2.2");
document.close();
}
}