Veröffentlicht 24. April 200619 j Hallo, ich hab dass Problem, dass ich eine Druckfunktion für HTML-Dateien geschrieben habe - allerdings funktioniert die noch nicht so wie ich will Es kommt immer die Exception "services must be non-null and non-emty" public void print(){ try { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8; PrintService printService[] = PrintServiceLookup.lookupPrintServices( flavor, pras); PrintService defaultService = PrintServiceLookup. lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(GraphicsEnvironment. getLocalGraphicsEnvironment(). getDefaultScreenDevice(). getDefaultConfiguration(), 200, 200, printService, defaultService, flavor, pras); [COLOR="Red"]// <-- da[/COLOR] if (service != null) { DocPrintJob job = service.createPrintJob(); job.addPrintJobListener(printerListener); FileInputStream fis = new FileInputStream(dir + "\\" + fileName); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); } } catch (ArrayIndexOutOfBoundsException ex) { ex.printStackTrace(); System.out.println("Keine Drucker gefunden!!"); } catch (Exception ex) { ex.printStackTrace(); } } weis jemand woran das liegen könnte ? ich hab mich zwar jetzt schon mit der Druck-API beschäftigt aber find nicht wirklich was brauchbares oder hat jemand bessere vorschläge wie man ein HTML-Dokument drucken kann ?
24. April 200619 j Autor zumindest druckt er jetzt: public void print(){ try { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; PrintService service = PrintServiceLookup.lookupDefaultPrintService(); if (service != null) { DocPrintJob job = service.createPrintJob(); job.addPrintJobListener(printerListener); FileInputStream fis = new FileInputStream(dir + "\\" + fileName); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); } } catch (ArrayIndexOutOfBoundsException ex) { ex.printStackTrace(); System.out.println("Keine Drucker gefunden!!"); } catch (Exception ex) { ex.printStackTrace(); } } allerdings druckt er jetzt nur die Tags bei DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8 kommt "invalid flavor"
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.