I am trying to send some text to the printer. I need only text printed, wrapped on the edge of the page and, if necessary, moving to another page.
Here is a minimal example of what I'm doing now:
@FXML
private void print() {
TextArea printArea = new TextArea(textArea.getText());
printArea.setWrapText(true);
printArea.getChildrenUnmodifiable().forEach(node -> node.setStyle("-fx-background-color: transparent"));
printArea.setStyle("-fx-background-color: transparent");
PrinterJob printerJob = PrinterJob.createPrinterJob();
if (printerJob != null && printerJob.showPrintDialog(textArea.getScene().getWindow())) {
if (printerJob.printPage(printArea)) {
printerJob.endJob();
} else {
}
} else {
}
}
As a result, printing is a gray background, which seems to be the control itself, as well as the scroll bar. Am I approaching this wrong? I feel like struggling with the API by customizing and typing a control instead of just sending text to print. A.
The example below was taken from the camera of my mobile phone, so the white paper looks a little light gray, but you can still see the gray background from the control and scroll bar.

source
share