I have this code for printing a html file.
I pass a String with the html code in textString.
class Print
{
public void Print(String textString)
{
DocFlavor dflavor = DocFlavor.STRING.TEXT_HTML;
PrintService[] services = PrintServiceLookup.lookupPrintServices(
dflavor , null);
PrintService defaultService = PrintServiceLookup
.lookupDefaultPrintService();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService service = ServiceUI.printDialog(null, 50, 50, services,
defaultService, dflavor , pras);
if (service != null)
{
DocPrintJob job = service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(textString, dflavor , das);
try
{
job.print(doc, pras);
}
catch (PrintException pe)
{
}
}
}
}
this is the complete error
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: services must be non-null and non-empty
at javax.print.ServiceUI.printDialog(Unknown Source)
at PrintHtml.printHtml(PrintHtml.java:24)