Code for printing an html file.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Code for printing an html file.

Threaded View

  1. #1
    Join Date
    Jul 2004
    Posts
    54

    Code for printing an html file.

    I have the following code for printing an html file from within a program.

    I pass a String with the html code in textString.

    I get this error message:
    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)

    Please help as I don't understand what is incorrect.

    Thanks,
    RON C

    Code:
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.ServiceUI;
    import javax.print.SimpleDoc;
    import javax.print.attribute.DocAttributeSet;
    import javax.print.attribute.HashDocAttributeSet;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    
    class PrintHtml
    {
    public void printHtml(String textString)
    {
    DocFlavor flavor = DocFlavor.STRING.TEXT_HTML;
    PrintService[] services = PrintServiceLookup.lookupPrintServices(
    flavor, null);
    PrintService defaultService = PrintServiceLookup
    .lookupDefaultPrintService();
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    PrintService service = ServiceUI.printDialog(null, 50, 50, services,
    defaultService, flavor, pras);
    if (service != null)
    {
    DocPrintJob job = service.createPrintJob();
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(textString, flavor, das);
    try
    {
    job.print(doc, pras);
    }
    catch (PrintException pe)
    {
    }
    }
    }
    }
    Last edited by Jamie; 04-07-2005 at 04:14 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center