Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

HTML-Dokument mit Java drucken

Empfohlene Antworten

Veröffentlicht

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 ?

  • 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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.