Java printing: Invalid Flavor when trying to print HTML content

Posted on 2004-11-03
Last Modified: 2008-03-05
I need to print the contents of an EditorPane. For this, I've searched and found example code for using DocFlavors from the javax.print package.
Here's a code fragment:
                DocFlavor flavor = DocFlavor.STRING.TEXT_HTML;
                PrintService service = PrintServiceLookup.lookupDefaultPrintService();
                // Create the print job
                DocPrintJob job = service.createPrintJob();
                String s="<HTML><HEAD><TITLE> New Document </TITLE></HEAD>"+"<BODY><h1>Hello there "
//error here       Doc doc = new SimpleDoc(s, flavor, null);
                System.out.println("Doc flavor is "+doc.getDocFlavor());
                // Print it
                job.print(doc, null);
}catch(exception e)
At the line marked 'error here', I get a ''sun.print.PrintJobFlavorException: invalid flavor"
This code is adapted from a similar one (
If you run the code listing at the above link, the program works for printing 'image/gif' and loading a gif image from a file inputstream.
If you change it to any form of text (text/plain, text/html etc) and try loading a text or HTML file-you get the same error.

Every place on the net seems to detail this error when using DocFlavor.
Any help would be appreciated.
Question by:hwssoft
    LVL 86

    Accepted Solution

    AFAIK you won't find support for non-binary formats generally. You'd be better rendering the html in a JEditorPane and printing that
    LVL 37

    Expert Comment

    LVL 37

    Expert Comment

    I consider the link I posted also valuable
    - Main idea: Is that flavor supported on your system/printer?
    - shows how to list the available flavors

    Author Comment


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    method argument as final 1 54
    Enhanced For loop vs ForEach Loop 4 43
    endX challenge 2 33
    mapAB Challlenge 35 55
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now