1

I'd like to read and change zoom level of named destinations in a pdf file using iText 7. Ive come up with the following code:

Map<String, PdfObject> names =
                    document.getCatalog().getNameTree(PdfName.Dests).getNames();

for (Map.Entry<String, PdfObject> dest : names.entrySet()) {
    if (dest.getValue().isArray()) {
        PdfArray arr = (PdfArray) dest.getValue();
        PdfName asName = arr.getAsName(1); //  /Fit
        arr.set(1, FitR);
        //System.out.println();
        arr.setModified();
    }
}

However, this code fails to work against my example file and has other flaws as well. Most importantly, it tries to deal with one type of zoom (/Fit), but other types (/XYZ and so on) should also be handled with. Second, I don't know how to get the page number of named destination as key pair named of destination and its zoom value doesn't seem to have this information. Please see a screenshot of debug session below:

enter image description here

Note, at SO there is already a question dealing with exactly the same topic. The thing is the answer to that question give too little information to deal with this problem.

menteith
  • 596
  • 14
  • 51

0 Answers0