Caros colegas
,
Estou tendo dificuldades em usar a api javax.print, nao consigo imprimir mais de uma copia, mesmo informado no printDialog. Ja tentei setar a quantidade de copias no codigo mas nao funciona. Detalhe: Ja executei testes no Windows e Linux e verifiquei que no Ubuntu 10.04 funcionou sem alterar nada.
Segue o codigo:
public static void printFile(File file) throws FileNotFoundException, PrintException {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
// Localiza a impressora padr�o.
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
// printAttributes.add(new PageRanges(0 + 1, XPTO + 1));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
HashDocAttributeSet docAttributeSet = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, docAttributeSet);
String os = System.getProperty("os.name");
// devido a um bug no linux, estamos evitando o dialog no linux (so ocorreu con versao anterio ao Ubuntun 10.04
if (!"Linux".equals(os.toString())) {
// Localiza todas as impressoras.
PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, docAttributeSet);
if (services != null && services.length > 0) {
PrintService service = ServiceUI.printDialog(null, 320, 240, services, defaultService, flavor, printAttributes);
defaultService = (service != null && services.length > 0)? service : null;
//Informando a quantidade de copias na marra.
CopiesSupported copSupp = (CopiesSupported) service.getSupportedAttributeValues(Copies.class, null,null);
if (copSupp != null && copSupp.contains(5)) {
printAttributes.add(new Copies(5));
}
}
}
if (defaultService != null) {
DocPrintJob job = defaultService.createPrintJob();
job.print(doc, printAttributes);
}
} finally {
try {
fis.close();
} catch (Exception lE) {
}
}
}