catch(Exception e)
{throw new RuntimeException(filePath + " file access error.",e);}
}
// 2. Modifying the document...
Document document = file.getDocument();
{
// Create the action dictionary!
PdfDictionary action = new PdfDictionary();
// Define the action type (in this case: go-to)!
action.put(new PdfName("S"),new PdfName("GoTo"));
// Defining the action destination...
{
// Create the destination array!
PdfArray destination = new PdfArray();
// Define the 2nd page as the destination target!
destination.add(document.getPages().get(1).getBaseObject());
// Define the location of the document window on the page (fit vertically)!
destination.add(new PdfName("FitV"));
// Define the window's left-edge horizontal coordinate!
destination.add(new PdfInteger(-32768));
// Associate the destination to the action!
action.put(new PdfName("D"),destination);
}
// Associate the action to the document!
document.getBaseDataObject().put(
new PdfName("OpenAction"),
file.register(action) // Adds the action to the file, returning its reference.
); document.update(); // Updates the existing document object (fundamental to override previous content).
}
// (boilerplate metadata insertion -- ignore it)
buildAccessories(document,"Primitive objects","manipulating a document at primitive object level");