Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Running JavaFX on a server

1 min read

JavaFX on the server???

Javafx_logo_color
Java FX on a Server? Is it the Future?

JavaFX is heavily promoted as a desktop technology to replace Swing. So it might seem slightly strange to suggest running it on a server. But JavaFX also offers a replacement for Graphics2D. We use Graphics2D extensively for creating images from PDF data. One of the popular uses for our Java PDF library is to convert PDF files to images on the server. Currently we use Graphics2D for this. So can you use JavaFX on your server, and how well does it run?

Reasons to use JavaFX in place of Graphics2D

We have found 3 reasons to use JavaFX:-

1. More Functionality. JavaFX offers a much more polished set of functions that Graphics2D. As an example, General shapes and paths have much more functionality in JavaFX and you do not need to convert them to Areas,

2. Less code. We have found that our JavaFX implementations have much less code than Graphics2D. This is partly because the API is better designed and partly because JavaFX has more functionality. My colleague Simon has a really interesting blog article on how much simpler blend modes are in JavaFX.

3. The Future. Swing will continue to be around but is unlikely to see any improvements. JavaFX is where all the action is and work is happening to make it run on as many platforms as possible.

An actual code example

Here is a simple code skeleton example. We recommend you run JavaFX on Java8.

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import org.jpedal.PdfDecoderFX;
/**
* Runs on the server as well
*/public class ServerFXExample extends Application{

@Override
public void start(Stage stage) throws Exception {

//Your JavaFX code

Platform.exit();
}

/**
* Main method to call on server
*/public static void main(String[] args) {

launch();

}
}

Some ‘caveats’

We have found only 2 real issues with JavaFX (which are more than out-weighed by the advantages listed above).

1. You will still need to use ImageIO for Image handling. There are Utilities classes to convert JavaFX images into BufferedImage (and back). So you will still need ImageIO (and JAI if you are working with JPEG2000 images). Image support in Java remains an achilles heel and it would be really nice to see some improvements.

2. Slightly slower Performance? We implemented a test case in JavaFX and another in Swing/Graphics2D and found a small hit (which we think is due to startup rather than generally being slower). I will do some more detailed investigations and document in a future article.

Overall, JavaFX is well worth investigating for the server as well as the desktop and we found it much quicker and  easier to develop Java applications with JavaFX. What are your experiences of JavaFX on the server?

This post is part of our “Java Articles Index“ series. In these articles, we aim to explore the world of Java and Javafx. Have a look through!

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 (Twitter, Facebook and Google+) or the Blog RSS.

 

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Updates on Java PDF Viewer roadmap from IDRsolutions

My previous blog post (5 changes we are considering in 2016 for IDRsolutions), generated lots of feedback for us (for which we would like...
Mark Stephens
58 sec read

My key takeaways from NetBeans Day 2015

NetBeans Day 2015 had to be rescheduled to bigger rooms because of attendee demand. It was a very busy schedule. Here are my notes...
Mark Stephens
2 min read

An Introduction to JavaFX Panes with Code Examples

As a developer at IDR Solutions I spend a lot of my time working with JavaFX and Panes in our JavaFX PDF Viewer. I...
Sylwia Dorota Kedzia
1 min read

Leave a Reply

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