diff --git a/build.gradle b/build.gradle index 176e4a2..10c8a00 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'FXPDFViewer' -version '0.3' +version '0.5' sourceCompatibility = 1.8 diff --git a/src/main/java/com/dansoftware/pdfdisplayer/PDFDisplayer.java b/src/main/java/com/dansoftware/pdfdisplayer/PDFDisplayer.java index 6418868..9dc585a 100644 --- a/src/main/java/com/dansoftware/pdfdisplayer/PDFDisplayer.java +++ b/src/main/java/com/dansoftware/pdfdisplayer/PDFDisplayer.java @@ -92,6 +92,7 @@ public void displayPdf(InputStream inputStream) throws IOException { } + @SuppressWarnings("all") public void setSecondaryToolbarToggleVisibility(boolean value) { setVisibilityOf("secondaryToolbarToggle", value); @@ -139,6 +140,22 @@ public void setVisibilityOf(String id, boolean value){ } } + public int getActualPageNumber(){ + try { + return (int) nodeValue.getEngine().executeScript("PDFViewerApplication.page;"); + } catch (Exception e) { + return 0; + } + } + + public int getTotalPageCount(){ + try { + return (int) nodeValue.getEngine().executeScript("PDFViewerApplication.pagesCount;"); + } catch (Exception e) { + return 0; + } + } + public void navigateByPage(int pageNum) { String jsCommand = "goToPage(" + pageNum + ");"; try { diff --git a/src/test/java/PageNavigationDemo.java b/src/test/java/PageNavigationDemo.java new file mode 100644 index 0000000..ed501bf --- /dev/null +++ b/src/test/java/PageNavigationDemo.java @@ -0,0 +1,31 @@ +import com.dansoftware.pdfdisplayer.PDFDisplayer; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +import java.net.URL; + +public class PageNavigationDemo extends Application { + + @Override + public void start(Stage primaryStage) throws Exception { + PDFDisplayer displayer = new PDFDisplayer(new URL("https://www.tutorialspoint.com/javafx/javafx_tutorial.pdf")); + + Button goToPage10 = new Button("Go to page 10"); + goToPage10.setOnAction(e -> { + displayer.navigateByPage(10); + }); + + primaryStage.setScene(new Scene(new VBox(displayer.toNode(), new StackPane(goToPage10)))); + primaryStage.show(); + + // + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/test/java/ProcessListenerDemo.java b/src/test/java/ProcessListenerDemo.java index 2089d5c..61bdc2e 100644 --- a/src/test/java/ProcessListenerDemo.java +++ b/src/test/java/ProcessListenerDemo.java @@ -15,7 +15,6 @@ public class ProcessListenerDemo extends Application { @Override public void start(Stage primaryStage) throws Exception { - //create a progressBar ProgressBar progressBar = new ProgressBar(); progressBar.setPrefWidth(500);