/************************************************************************* * * * EJBCA Community: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.ejbca.util; import java.awt.print.PageFormat; import java.awt.print.Paper; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.io.IOException; import java.io.StringReader; import javax.print.DocFlavor; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import org.apache.log4j.Logger; import org.cesecore.certificates.endentity.EndEntityInformation; import org.ejbca.core.model.hardtoken.profiles.SVGImageManipulator; /** * Class managing EJBCA print functionality, such as listing printers * and managing printjobs * * @author Philip Vendil 2006 sep 20 * * @version $Id: PrinterManager.java 22117 2015-10-29 10:53:42Z mikekushner $ */ public class PrinterManager { private static Logger log = Logger.getLogger(PrinterManager.class); private static transient PrintService currentService = null; private static transient String currentPrinterName = null; private static transient String currentSVGTemplateName = null; private static transient SVGImageManipulator sVGImagemanipulator = null; /** * Method that returns the names of all the available printers or an empty list if * no printers were found or an error occurred. */ public static String[] listPrinters(){ String[] printerNames = new String[0]; try { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); printerNames = new String[printService.length]; for(int i=0;iprint: "+endEntityInformation.getUsername()+", "+printerName); } if(currentService == null || currentPrinterName == null || !printerName.equals(currentPrinterName)){ PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); int i = 0; String trimemdPrinterName = printerName.trim(); while ( i