https://kotlinlang.org logo
#getting-started
Title
# getting-started
j

Jasin Colegrove

01/05/2022, 12:39 PM
Does anyone have any advice on printing documents from a kotlin desktop app? I need to be able to create printable documents from database data. I've looked at PDFBox (create PDF's that can later be printed) but I really want a clean idiomatic kotlin way of doing it?
i

Ivan Zinchenko

01/05/2022, 12:42 PM
pretty sure there is no Kotlin “idiomatic” way here 🙂 good old Java AWT could help: https://docs.oracle.com/javase/tutorial/2d/printing/printable.html
another way could be some IPP lib, there are Kotlin implementations, for example: https://github.com/gmuth/ipp-client-kotlin
j

Jasin Colegrove

01/05/2022, 1:02 PM
i'm using tornadofx so I'm thinking it might be possible to implement this https://docs.oracle.com/javase/8/javafx/api/javafx/print/PrinterJob.html
i

Ivan Zinchenko

01/05/2022, 1:09 PM
should also work, don’t know details of your use case, but it seems IPP is the most universal solution, since you’ve mentioned you need to print random documents
j

Jasin Colegrove

01/05/2022, 1:56 PM
well the documents would be created from my app. If I can avoid that intermediate step by just printing the data straight from javafx that seems a better solution, provided I can get it to scale correctly to a sheet of paper.
r

Ruckus

01/05/2022, 4:11 PM
Getting the data to fit correctly on a page is exactly what "creating a document" means. It's basically just taking data and associating layout information with it.
j

Jasin Colegrove

01/05/2022, 4:51 PM
unless I am missing something it seems ipp needs a formatted document to process for printing. One of the issues I am having is figuring out a way to get the data formatted to a printable document.
5 Views