Sylwia Dorota Kedzia

Sylwia is a developer at IDR Solutions working on JavaFX Development and on the NetBeans JavaFX Plugin. She is very passionate about programming and aims to improve constantly.

Integrating PDF to HTML5 conversion into NetBeans platform – WebView and JavaFx clients.

2 min read

Working with PDF to HTML5 conversion and NetBeans IDE on daily basis at IDR solutions, I had an idea of combining the two. Therefore in this blog post I am going step you through the process of integrating PDF to HTML5 conversion into the NetBeans platform.

Requirements:

– NetBeans
– Java8
– 16×16 image (optional)

There are two ways of integrating PDF to HTML5 conversion into NetBeans platform, you can ether create a JavaFX project or a NetBeans plug-in. In this article I will show you how you can do both.

JavaFX project

The creation of JavaFX project in NetBeans is very simple as all what you have to do is:

New Project > JavaFX > JavaFx Application > Type Project Name > Finish

1 2

Next replace the start method with the following code:

double height;
double width;

@Override
public void start(Stage primaryStage) {

    WebView converter = new WebView();
    converter.getEngine().load("https://convert.idrsolutions.com");

    Scene scene = new Scene(converter, this.width, this.height);

    primaryStage.setTitle("Pdf To HTML5");
    primaryStage.setScene(scene);
    primaryStage.show();
}

And that’s all. In this project you are using WebView component that is UI component that allows WebView and full browsing functionality through its API. In the converter.getEngine().load(“https://convert.idrsolutions.com”); line of code, the URL points to our free online converter where you can upload your own PDF file and convert it to HTML5.

4    5

Create NetBeans plug-in

If you want your converter to be built in the NetBeans IDE I would suggest you write a NetBeans plug-in and here is how to do it:

Select New Project > NetBeans Modules > Module >

11

Type Project Name > Next >

12
Type Code Name Base > Finish

12

Once your Plug-in is created right click on the org package > New > Action >

14

Accept the default settings > Next

15

Select Category and tick all the boxes as shown on the image below. If you are not planning to upload an icon image untick the Global Toolbar Button box and press Next.

16
Type the Class Name and Display Name > Finish.

17
Again right click on the org package > New > Window >

18

Select editor in the Window Position option > Next

19

Type Class Name Prefix, notice that the Class Name Prefix must differ from the Class Name in the Action Class. You can also select icon here. > Finish

20

Adding the Code to the TopComponent class:

Under the

public final class PdfToHtml5TopComponent extends TopComponent {

line of code insert the following code:

JFXPanel jfxPanel = new JFXPanel();
double height;
double width;
Scene scene;
WebView convert;

Replace the componentOpened() and componentClosed() methods with the following code:

@Override
public void componentOpened() {
    // TODO add custom code on component opening
    this.setLayout(new BorderLayout());
    this.add(jfxPanel, BorderLayout.CENTER);

    Platform.setImplicitExit(false);
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            initFX();
        }
    });
}

public void initFX() {
    Scene scene = Browse(this.getBounds().width, this.getBounds().height);
    jfxPanel.setScene(scene);
}

@Override
public void componentClosed() {
    convert.getEngine().load(null);
}

Replace Browse method with the following code:

private Scene Browse(int width, int height) {
    this.height = height;
    this.width = width;
    convert = new WebView();

    BorderPane borderPane = new BorderPane();
    borderPane.setCenter(convert);

    convert.getEngine().load("http://convert.idrsolutions.com");
    scene = new Scene(borderPane, this.width, this.height);
    return scene;
}

Adding the Code to the Action class:

Replace the actionPerformed method with the following code:

@Override
public void actionPerformed(ActionEvent e) {
    TopComponent tc;
    tc = new PdfToHtml5TopComponent();//Type the name of your TopComponent class name
    tc.open();
    tc.requestActive();
}

And finally right click on the project and select Install/Reload in Development IDE

22

Once that’s done the new icon of your PDF to HTML converter should appear on the tool bar as well as in the File option. If you click on it, the PDF to HTML5 online convertor will open in your NetBeans editor section.

34

Now you can convert PDF, Word, Excel and PowerPoint files in your NetBeans IDE.

37  pp

aaa aa

 

For additional functionality of your NetBeans plug-in please check my previous article “How to write a WebBrowser plugin in JavaFX for the NetBeans IDE“, and for additional reading on PDF to HTML Conversion check our free E-books.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (TwitterFacebook and Google+) or the Blog RSS.

Sylwia Dorota Kedzia

Sylwia is a developer at IDR Solutions working on JavaFX Development and on the NetBeans JavaFX Plugin. She is very passionate about programming and aims to improve constantly.

Hacking the NetBeans IDE – 4. Changing the way…

To help us prepare for our talks for our talks at Oracle CodeOne – “Writing Better Code (Faster) in the Apache NetBeans IDE ” and “Hacking...
Mark Stephens
1 min read

3 Replies to “Integrating PDF to HTML5 conversion into NetBeans platform –…”

  1. Good job.
    Is there a way this can be achieved ofline by downloading converter jar. Secondly, can the file display alongside another plane (embeded)?
    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *