java - Bookmarks in a pdf not going to the correct pages nor any page for that matter. Why is this happening? -


i'm using netbeans , itext pdf api. have following method creates hashtable can inserted pdf. in case image files placed in pdf @ end of document.

private hashmap<string, object> newtmp = new hashmap<>(); //to generate bookmarks images, object made private arraylist<hashmap<string, object>> bookmarks = new arraylist<>(); //an array list instantiated bookmarks saved  private void bookmarkgen(string imagelist[]) { int n = 0; //counter used progress each bookmark.     (int = 0; < imagelist.length; i++) {         if (imagelist[i] != null) {             bookmarks.add(newtmp);             newtmp.put("title", imagelist[i].substring(imagelist[i].lastindexof("/"), imagelist[i].lastindexof(".")));             newtmp.put("action", "goto");             newtmp.put("page", string.format("%d fit", n++));             system.out.print(n + "\n");             system.out.print("bookmark added\n");         }     } } 

the next part of process involves following lines of code input bookmarks pdf.

    if (!bookmarks.isempty() && pdfcounter > 0) {         copy.setoutlines(bookmarks);         system.out.println("bookmarks have been outlined");     } 

whenever this, 1 of bookmarks go 1 page , rest don't have page assigned. doing wrong?

you create newtmp once , add list multiple times, overwriting entries each time. thus, have list containing many references newtmp values set in last iteration of loop.

to fix this, move

private hashmap<string, object> newtmp = new hashmap<>();  

into loop.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -