title: Printing an image with some text in java
body: <p>I need to print on a printer an image and some data, in java (Swing)  but all in vain. I am just able to do up with the data but not with the image. I have a abc.png file and 6 jTextBoxes, from which the value has to be printed on the printer. I am using the FileWriter and PrinterJob classes to implement the job. The data and the image can be printed separately but not together. Can somebody suggest me something.</p>
  
  <p>Thanks.</p>
  
  <p>Code for printing image:</p>
  
  <pre><code>try {
  PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
  pras.add(new Copies(1));
  
  PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF,     pras);
  
  if (pss.length == 0)
  throw new RuntimeException("No printer services available.");
  
  PrintService ps = pss[0];
  System.out.println("Printing to " + ps);
  
  DocPrintJob job = ps.createPrintJob();
  
  FileInputStream fin = new FileInputStream("C://a.gif");
  
  
  Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
  
  //Doc doc1=new SimpleDoc();
  
  
  
  job.print(doc, pras);
  
  //fin.close();
  } catch (IOException ie) {
  ie.printStackTrace();
  } catch (PrintException pe) {
  pe.printStackTrace();
  }
  </code></pre>
  
  <p>Code for printing text:</p>
  
  <p>Just pass the location of the file on the hard disk, in FileInputStream.</p>