try
{file = new File(filePath);}
catch(Exception e)
{throw new RuntimeException(filePath + " file access error.",e);}
}
Document document = file.getDocument();
// 2. Applying actions...
// 2.1. Local go-to.
{
DocumentActions documentActions = document.getActions();
if(documentActions == null)
{
document.setActions(documentActions = new DocumentActions(document));
document.update();
}
/*
NOTE: This statement instructs the PDF viewer to go to page 2 on document opening.
*/
documentActions.setOnOpen(
new GoToLocal(
document,
new LocalDestination(
document.getPages().get(1), // Page 2 (zero-based index).
Destination.ModeEnum.Fit,
null
)
)
);
documentActions.update();
}
// 2.2. Remote go-to.
{
Page page = document.getPages().get(1); // Page 2 (zero-based index).
PageActions pageActions = page.getActions();
if(pageActions == null)
{
page.setActions(pageActions = new PageActions(document));
page.update();