This discussion is archived
3 Replies Latest reply: Jun 20, 2012 2:42 AM by gimbal2 RSS

How to print Bufferred Image to a printer in java?

944659 Newbie
Currently Being Moderated
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=""

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/x-java-jvm-local-objectref; class="java.awt.print.Printable"

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

application/octet-stream; class=""

application/octet-stream; class=""

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.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points