This sample shows how to add a Link in a PDF document with a LaunchAction with specified open preferences:
- Open in a new window: Action.OPEN_NEW_WINDOW
- Open in the existing window: Action.OPEN_EXISTING_WINDOW
- Window set by user preference: Action.OPEN_USER_PREFERENCE
// create a new link Link link = page.getDocument().getAnnotationFactory().createLink(); // show blue border around the link link.setRectangle(bounds); link.setBorderWidth(1f); link.setColor(Color.blue); // Create launch action with new window LaunchAction action = new LaunchAction(path, Action.OPEN_NEW_WINDOW); // Create launch action with existing window //LaunchAction action = new LaunchAction(path, Action.OPEN_EXISTING_WINDOW); // Create launch action with user window preference //LaunchAction action = new LaunchAction(path, Action.OPEN_USER_PREFERENCE); // Add launch action to the link Vector<LaunchAction> actionList = new Vector<LaunchAction>(); actionList.add(action); link.setActions(actionList); // Add the link to the page page.addAnnotation(link); |
Download Full Java Sample to Create Links with Launch Actions