Learn how to a build a cloud-first strategyRegister Now


Java printing: Invalid Flavor when trying to print HTML content

Posted on 2004-11-03
Medium Priority
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 (http://javaalmanac.com/egs/javax.print/WaitForDone.html)
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
  • 2
LVL 86

Accepted Solution

CEHJ earned 1000 total points
ID: 12482703
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

ID: 12681563
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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