9-Pin
9-Pin

Reputation: 436

Using iText, Cannot Replicate PDF Bookmark Destinations Created from InDesign/FrameMaker

I am writing a utility to collapse the bookmarks an exisiting PDF, and save the file as a new PDF. The platform is Java using the iText API.

The following code retrieves the existing bookmarks and recursively calls a method to close them.

/* Retrieve the bookmarks: */
List<HashMap<String, Object>> bookmarks = SimpleBookmark.getBookmark(originalPdf);
/* Now we recursively close all the bookmarks.*/
if (bookmarks != null ) {
  for (HashMap temp : bookmarks) {
    closeBookmark(originalPdf, temp, "false");
  }
}

private static void closeBookmark(PdfReader originalPdf, HashMap localBookmark, String bookmarkState) {
  localBookmark.put("Open", bookmarkState);
/* If the current bookmark has kids (lower-level bookmarks), then recursively close them as well. */
  if (localBookmark.containsKey("Kids")) {
    ArrayList<HashMap> kidMap = (ArrayList) localBookmark.get("Kids");
      for (HashMap temp : kidMap) {
        closeBookmark(originalPdf, temp, bookmarkState);
      }
    }
}

This works on PDFs created by Word, OpenOffice, and XSL-FO, but not FrameMaker or InDesign. In the latter cases, I get the collapsed bookmarks, but clicking on the bookmarks does not scroll the PDF to the destination. It seems as if the destinations are not present in either the bookmarks or the PDF body. Any suggestions?

Upvotes: 0

Views: 123

Answers (0)

Related Questions