3 Replies Latest reply on Jun 20, 2012 9:42 AM by gimbal2

    How to print Bufferred Image to a printer in java?

      I have a bufferredImage object and I want to send it to a printer through my code. The following are the supported types for my printer:

      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"

      I have been successful by saving the buferredImage to a disk and then reopening it as fileInputStream and sending it to a print. But I want to do send the buferred image directly for printing.
      I tried the following method:

      DocFlavor dsc =

      ByteArrayOutputStream os = new ByteArrayOutputStream();

      try {
      ImageIO.write(image, "png", os);

      } catch (IOException e1) {

      InputStream is = new ByteArrayInputStream(os.toByteArray());

      // create the doc to be sent to the printer
      Doc doc =
      new SimpleDoc(is, dsc, null);

      and then sent the doc for printing but I am getting this exception - Unable to print document. Doc format not supported
      So how I supposed proceed from now on.