Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JPS Error -> "Invalid Doc Flavor"

Thread Tools

JPS Error -> "Invalid Doc Flavor"

Posts: n/a
I want to use the Java Print Service(JPS) API to programatically send
PDF files to a printer. I need to send these files to the printer
without any user intervention.

I am able to print text files but have not been successfull in printing
PDF files. The error I recieve is "Invalid Flavor". Below are the
Document Flavors that my printer supports:

image/gif; class="[B"
image/gif; class=""
image/gif; class=""
image/jpeg; class="[B"
image/jpeg; class=""
image/jpeg; class=""
image/png; class="[B"
image/png; class=""
image/png; class=""
application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"

application/octet-stream; class="[B"
application/octet-stream; class=""
application/octet-stream; class=""

In addition to the above Flavors I have tried sending the PDF to the
printer using a Document Flavor of INPUT_STREAM.AUTOSENSE. When I do
this the PDF file gets sent to the printer but what actually gets
printed is garbage (control characters, overtyping, etc...).

It appears the printer does not directly support PDF printing. The
interesting thing is that I if I bring up a PDF file using Adobe Reader
and press the Print button the file does get printed successfully!

Can someone help me explain why Adobe Reader can print the file
successfully but I am unable to do it programattically? Can someone
suggest a different approach to take?


Reply With Quote
Thomas Weidenfeller
Posts: n/a
MattC wrote:
> Can someone help me explain why Adobe Reader can print the file
> successfully but I am unable to do it programattically? Can someone
> suggest a different approach to take?

Because Acrobat Reader understands PDF! I mean, it's the whole job of
Acrobat Reader to understand PDF. It gets the PDF, it converts it to the
platform's print format, and it prints the stuff.

On the other hand, your operating system doesn't know about PDF. Why
should it? You are expecting black magic.

So, you can

1) Tell your operating system how to handle PDF, e.g. by adding a PDF
printer driver (if you can find one). You also have to hope that Java
will pick up the driver and provide you with a matching doc flavor. Good

2) Use Acrobat Reader. Check the documentation, there is AFAIK a command
line option in Acrobat Reader to print PDF documents from the command
line, or to convert them to PostScript.

3) Use GNU GhostScript to read PDF and format it for a particular printer.


The FAQ:
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How does 'jps' identify all the JVMs on the current host? John Java 1 11-17-2005 09:03 PM
quantity of JPS's/Servlets vs. resource consuming Przemek Klein Java 0 10-06-2005 12:20 PM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
Having trouble printing with JPS, Invalid flavor Brennan Mann Java 0 07-03-2004 07:48 PM
JPS 1.4: unit of measurement in the printDialog() =?ISO-8859-1?Q?J=F6rg_Marti?= Java 0 08-12-2003 06:18 AM