org.jpedal.examples.viewer.utils.PrintStatus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of OpenViewerFX Show documentation
Show all versions of OpenViewerFX Show documentation
Open Source (LGPL) JavaFX PDF Viewer
/*
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.idrsolutions.com
* Help section for developers at http://www.idrsolutions.com/support/
*
* (C) Copyright 1997-2017 IDRsolutions and Contributors.
*
* This file is part of JPedal/JPDF2HTML5
*
@LICENSE@
*
* ---------------
* PrintStatus.java
* ---------------
*/
package org.jpedal.examples.viewer.utils;
import java.awt.print.PrinterJob;
import javax.print.PrintService;
import org.jpedal.utils.PrintUtils;
/**
*
* @author markee
*/
public class PrintStatus {
//flag to stop mutliple prints
static int printingThreads;
public static boolean isPrinting() {
return printingThreads > 0;
}
public static String[] getAvailablePrinters(final String blacklist) {
//Refresh list in case it has changed
PrintUtils.refreshPrinterList();
final PrintService[] service = PrinterJob.lookupPrintServices();
final int noOfPrinters = service.length;
String[] serviceNames = new String[noOfPrinters];
//check blacklist
if (blacklist != null) {
final String[] bl = blacklist.split(",");
int count = 0;
//loop through printservices
for (final PrintService aService : service) {
boolean pass = true;
final String name = aService.getName();
//loop through blacklist items
for (final String aBl : bl) {
//check for wildcard
if (aBl.contains("*")) {
final String term = aBl.replace("*", "").trim();
if (name.contains(term)) {
pass = false;
}
} else if (name.equalsIgnoreCase(aBl.toLowerCase())) {
pass = false;
}
}
//Add to array
if (pass) {
serviceNames[count] = name;
count++;
}
}
//Trim array
final String[] temp = serviceNames;
serviceNames = new String[count];
System.arraycopy(temp, 0, serviceNames, 0, count);
} else {
for (int i = 0; i < noOfPrinters; i++) {
serviceNames[i] = service[i].getName();
}
}
return serviceNames;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy