You will need to get border pane in your current window pane
/**
* FXML Controller class
*
* @author Sudarshan
*/
public class PDFFXMLController implements Initializable {
private static String pdfPath;
private SwingController swingController;
private JComponent viewerPanel;
@FXML
private BorderPane borderPane;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
String pdfPathLoad;
try {
pdfPathLoad = loadPDF("http://21-04-2017/17854381660C617.pdf");
createViewer(borderPane);
openDocument(pdfPathLoad );
} catch (IOException ex) {
Logger.getLogger(PDFFXMLController.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void createViewer(BorderPane borderPane) {
try {
SwingUtilities.invokeAndWait(() -> {
swingController = new SwingController();
swingController.setIsEmbeddedComponent(true);
PropertiesManager properties = new PropertiesManager(System.getProperties(),
ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));
properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_FIT, "false");
properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ROTATE, "false");
properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_TOOL, "false");
properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.25");
properties.setBoolean(PropertiesManager.PROPERTY_SHOW_STATUSBAR_VIEWMODE, Boolean.FALSE);
properties.set(PropertiesManager.PROPERTY_SHOW_TOOLBAR_PAGENAV, "false");
ResourceBundle messageBundle = ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE);
new FontPropertiesManager(properties, System.getProperties(), messageBundle);
swingController.getDocumentViewController().setAnnotationCallback(
new org.icepdf.ri.common.MyAnnotationCallback(swingController.getDocumentViewController()));
SwingViewBuilder factory = new SwingViewBuilder(swingController, properties);
viewerPanel = factory.buildViewerPanel();
viewerPanel.revalidate();
SwingNode swingNode = new SwingNode();
swingNode.setContent(viewerPanel);
borderPane.setCenter(swingNode);
swingController.setToolBarVisible(false);
swingController.setUtilityPaneVisible(false);
});
} catch (InterruptedException | InvocationTargetException e) {
}
}
private void openDocument(String document) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
swingController.openDocument(document);
viewerPanel.revalidate();
}
});
}
public String loadPDF(String adresse) throws IOException {
System.out.println("In load PDf");
if (!adresse.toLowerCase().endsWith("pdf")) {
return null;
}
String fileName = adresse.substring(adresse.lastIndexOf("/") + 1,
adresse.lastIndexOf("."));
String suffix = adresse.substring(adresse.lastIndexOf("."),
adresse.length());
File temp = null;
try {
InputStream input = new URL(adresse).openStream();
temp = File.createTempFile(fileName, suffix);
temp.deleteOnExit();
Files.copy(input, Paths.get(temp.toURI()),
StandardCopyOption.REPLACE_EXISTING);
} catch (MalformedURLException ex) {
Logger.getLogger(PDFFXMLController.class.getName()).log(Level.SEVERE, null, ex);
}
return temp.getAbsolutePath();
}
}