From 12fc41639a795408c8fa6f6878c8f972579a0a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Fri, 26 Nov 2021 17:46:17 +0100 Subject: [PATCH] do not return a printer if printer name does not match --- .../graphics/pdfbox/print/PrintUtility.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/graphics-pdfbox-print/src/main/java/org/xbib/graphics/pdfbox/print/PrintUtility.java b/graphics-pdfbox-print/src/main/java/org/xbib/graphics/pdfbox/print/PrintUtility.java index ab76835..73bfb15 100644 --- a/graphics-pdfbox-print/src/main/java/org/xbib/graphics/pdfbox/print/PrintUtility.java +++ b/graphics-pdfbox-print/src/main/java/org/xbib/graphics/pdfbox/print/PrintUtility.java @@ -27,9 +27,6 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; -/** - * - */ public class PrintUtility { public static void print(InputStream inputStream, DocFlavor docFlavor) @@ -96,22 +93,20 @@ public class PrintUtility { job.print(); } + public static Printer getDefaultPrinter() { + return createPrinter(PrintServiceLookup.lookupDefaultPrintService()); + } + public static Printer getPrinter(String printerName, DocFlavor docFlavor) { - Printer printer = null; if (printerName != null) { List printers = findPrinters(docFlavor); for (Printer p : printers) { if (printerName.equalsIgnoreCase(p.getName())) { - printer = p; - break; + return p; } } } - if (printer == null) { - PrintService service = PrintServiceLookup.lookupDefaultPrintService(); - printer = createPrinter(service); - } - return printer; + return null; } public static Printer findDefaultPrinter(DocFlavor docFlavor) { @@ -141,7 +136,6 @@ public class PrintUtility { if (attr != null) { printer.setModel(attr.toString()); } - //attr = service.getAttribute( PrinterIsAcceptingJobs.class ); printer.setStatus(Printer.STATUS_ACCEPTING_JOBS); attr = service.getAttribute(PrinterInfo.class); if (attr != null) {