JPS Error -> "Invalid Doc Flavor"

Discussion in 'Java' started by MattC, Jul 22, 2005.

  1. MattC

    MattC Guest

    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
    MattC, Jul 22, 2005
    #1
    1. Advertising

  2. 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
    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

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
    Thomas Weidenfeller, Jul 25, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?J=F6rg_Marti?=

    JPS 1.4: unit of measurement in the printDialog()

    =?ISO-8859-1?Q?J=F6rg_Marti?=, Aug 12, 2003, in forum: Java
    Replies:
    0
    Views:
    346
    =?ISO-8859-1?Q?J=F6rg_Marti?=
    Aug 12, 2003
  2. Brennan Mann
    Replies:
    0
    Views:
    2,874
    Brennan Mann
    Jul 3, 2004
  3. Przemek Klein
    Replies:
    0
    Views:
    367
    Przemek Klein
    Oct 6, 2005
  4. John
    Replies:
    1
    Views:
    405
    Roedy Green
    Nov 17, 2005
  5. Thomas Feuerstack
    Replies:
    1
    Views:
    875
    Thomas Weidenfeller
    Dec 14, 2005
Loading...

Share This Page