I am trying to print an image using api's. Unfortunately, it reduces part of the image by about 25%, and then stretches it to the entire A4 page and prints it. What am I doing wrong with the print code. How can I specify that the image is on the page for printing, regardless of what the printer is. Please let me know.
The code:
public void printThis() {
System.out.println("I was called");
String path = "resources/img/printouts/image.png";
Image image = new Image(getClass().getResource(path).toExternalForm());
ImageView imageView = new ImageView(image);
new Thread(() -> printImage(imageView)).start();
}
public void printImage(ImageView image) {
Printer printer = Printer.getDefaultPrinter();
PrinterJob printJob = PrinterJob.createPrinterJob(printer);
PageLayout pageLayout = printJob.getJobSettings().getPageLayout();
printJob.getJobSettings().setPageLayout(pageLayout);
if (printJob != null) {
boolean success = printJob.printPage(image);
if (success) {
printJob.endJob();
}
}
}
Please let me know what I am doing wrong. Thank.: -)
source
share