Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Running JavaFX on a server

1 min read

JavaFX on the server???

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 than 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{

public void start(Stage stage) throws Exception {

//Your JavaFX code


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



Some ‘caveats’

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

1. You will still need to use ImageIO for Image handling. There are Utility 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 documents 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 with 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!


Are you a Developer working with PDF files?

Our developers guide contains a large number of technical posts to help you understand the PDF file Format.

Do you need to solve any of these problems?

Display PDF documents in a Web app
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

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

Leave a Reply

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

IDRsolutions Ltd 2022. All rights reserved.