Using iText
we can easily change zoom level for links. There is even a piece of code that does this for GoTo
destination type. For convienence, please find it below.
PdfReader reader = new PdfReader(src);
PdfDictionary page = reader.getPageN(11);
PdfArray annots = page.getAsArray(PdfName.ANNOTS);
for (int i = 0; i < annots.size(); i++) {
PdfDictionary annotation = annots.getAsDict(i);
if (PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE))) {
PdfArray d = annotation.getAsArray(PdfName.DEST);
if (d != null && d.size() == 5 && PdfName.XYZ.equals(d.getAsName(1)))
d.set(4, new PdfNumber(0));
}
}
The code deals only with one of destination types found in PDF files. I'm interested in changing zoom in other types of destinations (they are listed in 32000-1 if anyone wondered). Specifically, I'd like to change each destination to GoTo
type and specify my own coordinates. I want left coordinate to be the same as the page height of the page to jump. To do this, I obviously I need the page number. How do I get it?
What have I done so far?
The instruction PdfArray d = annotation.getAsArray(PdfName.DEST)
gives su an array where its first (0 based) element is page reference and not page number as Bruno Lowagie explains in his iText in Action, 2nd edition, p. 202). The array looks like this:
[1931 0 R, /XYZ, 0, 677, 0]`. I cannot find correct command to get page number on my own hence this post.