DocPrintJob: getAttributes() : DocPrintJob « javax.print « Java by API






DocPrintJob: getAttributes()

  

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;

import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.Attribute;
import javax.print.attribute.HashPrintJobAttributeSet;
import javax.print.attribute.PrintJobAttributeSet;
import javax.print.attribute.standard.JobMediaSheetsCompleted;
import javax.print.event.PrintJobAttributeEvent;
import javax.print.event.PrintJobAttributeListener;

public class Main {
  public static void main(String[] argv) throws Exception {
    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
        .lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);

    DocPrintJob job = service.createPrintJob();
    PrintJobAttributeSet set = new HashPrintJobAttributeSet(job.getAttributes());
    set.add(new JobMediaSheetsCompleted(0));
    job.addPrintJobAttributeListener(new MyPrintJobAttributeListener(), set);
  }
}

class MyPrintJobAttributeListener implements PrintJobAttributeListener {
  public void attributeUpdate(PrintJobAttributeEvent pjae) {
    Attribute[] attrs = pjae.getAttributes().toArray();
    for (int i = 0; i < attrs.length; i++) {
      String attrName = attrs[i].getName();
      String attrValue = attrs[i].toString();
    }
  }
}

   
    
  








Related examples in the same category

1.DocPrintJob: addPrintJobListener(PrintJobListener listener)
2.DocPrintJob: print(Doc doc, PrintRequestAttributeSet attributes)