JPS Error -> "Invalid Doc Flavor"

M

MattC

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="java.io.InputStream"
image/gif; class="java.net.URL"
image/jpeg; class="[B"
image/jpeg; class="java.io.InputStream"
image/jpeg; class="java.net.URL"
image/png; class="[B"
image/png; class="java.io.InputStream"
image/png; class="java.net.URL"
application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"

application/x-java-jvm-local-objectref;
class="java.awt.print.Printable"
application/octet-stream; class="[B"
application/octet-stream; class="java.net.URL"
application/octet-stream; class="java.io.InputStream"

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?

Thanks,
Matt
 
T

Thomas Weidenfeller

MattC said:
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
luck.

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.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top