I am trying to print a generated pdf file in a java fx but all the examples I have seen are for printing java fx nodes. I could have used the ordinary printing api but the print dialog it shows is swing based and is like a totally different application in both behaviour and appearance, which may confuse users.
I'd like to show a dialog prior to printing so that users can choose their preferred printer and also change page setup if possible. According to the open jdk wiki this was expected in java 8
1) PrinterJob - the class that controls the printing process and provides support for
* print and page setup dialogs which will be the platform native dialog at least on Windows and Mac OS X.
and the related jira issue is marked as fixed
PrinterJob class and the javafx print package has two issues(as far as I can tell):
So how can I provide a printing dialog in java fx to help users print pdf documents?
PS: I'm using Java 8 update 20 in a desktop environment (Windows 7 64 bit)
Any pointers are appreciated.
If you use Java8 you can print only Nodes (as far i know). But you can create an ImageView that renders an image you can print. If you want to print an pdf take a look at https://www.idrsolutions.com/javafx-pdf-viewer or any other javafx PDF viewer.
You can render the pdf in a Node (PDF Viewer) and print this.
But if you want an Printing Dialog, I think you must build your own.
But thats not realy hard.
You can use all the Information given from the Printer classes for example:
ObservableList<PaperSource> paperSources = FXCollections.observableArrayList(); paperSources.add(PaperSource.AUTOMATIC); paperSources.add(PaperSource.BOTTOM); ... PrintQuality.values() PrintSides.values() ...