Hello All,
Does anyone have a code sample of how to add bookmarks to the existing PDFs?
I have a code to merge the existing PDF but finding it difficult to add bookmarks. The bookmarks need to be added before the PDfs are merged ? Any help would be appreciated.
<b>code to merge existing PDFs</b>
public class Concat {
public static void main(String[] args) {
files<InputStream> files = new Arrayfiles<InputStream>();
try {
files.add(new FileInputStream(new File("c:/annual.pdf")));
files.add(new FileInputStream(new File("c:/semiannual.pdf")));
OutputStream out = new FileOutputStream(new File("c:/christey/reportSummary.pdf"));
Concat(files, out);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void Concat(files<InputStream> files, OutputStream outputStream)
throws DocumentException, IOException {
Document document = new Document();
PdfCopy copy = new PdfCopy(document, outputStream);
document.open();
for (InputStream in : files) {
PdfReader reader = new PdfReader(in);
for (int i = 1; i <= reader.getNumberOfPages(); ++i) {
document.newPage();
copy.addPage(copy.getImportedPage(reader, i));
}
}
outputStream.flush();
document.close();
outputStream.close();
}
}
thanks you!!!