javafx webEngine.print empty pages at the end

354 Views Asked by At

I'm trying to print my webEngine with print method, and an issue I have is an extra empty page after all the content is printed. I wonder what it could be or how to troubleshoot that issue?

public class JSPrintHook {
    public void print() {
        PrinterJob job = PrinterJob.createPrinterJob();
        if (job != null && job.showPrintDialog(webView.getScene().getWindow())) {
                webView.getEngine().print(job);
                job.endJob();
        }
    }
}
1

There are 1 best solutions below

1
On

It can be a thread handling problem, if you use WebEngine without javafx.application.Application (eg. integrate JavaFX to Swing UI). In this case you should use Platform.runLater(). For example:

Platform.runLater(new Runnable() {
    @Override
    public void run() {
        // print
    }
});