package com.qmth.qrzk.repository.utils;

import java.io.*;
import javax.print.*;
import javax.print.attribute.*; 
import javax.print.attribute.standard.*; 
  
public class PrintTest{
  
   public static void main(String args[]){
       
        FileInputStream psStream = null;
        try {
            psStream = new FileInputStream("d:/my.txt");
            } catch (FileNotFoundException ffne) {
              ffne.printStackTrace();
            }
            if (psStream == null) {
                return;
            }
        DocFlavor psInFormat = DocFlavor.INPUT_STREAM.JPEG;
        Doc myDoc = new SimpleDoc(psStream, psInFormat, null);  
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);
         
        // this step is necessary because I have several printers configured
        PrintService myPrinter = null;
        for (int i = 0; i < services.length; i++){
        	DocFlavor[] svcName = services[i].getSupportedDocFlavors();           
        	for(int j = 0;j < svcName.length;j++){
        		System.out.println("service found:"+svcName[i].getMediaType());
        	}
            
        }
         myPrinter = services[0];
        if (myPrinter != null) {            
            DocPrintJob job = myPrinter.createPrintJob();
            try {
            job.print(myDoc, aset);
             
            } catch (Exception pe) {pe.printStackTrace();}
        } else {
            System.out.println("no printer services found");
        }
   }
}
