當前位置: 首頁>>代碼示例>>Java>>正文


Java DocPrintJob類代碼示例

本文整理匯總了Java中javax.print.DocPrintJob的典型用法代碼示例。如果您正苦於以下問題:Java DocPrintJob類的具體用法?Java DocPrintJob怎麽用?Java DocPrintJob使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DocPrintJob類屬於javax.print包,在下文中一共展示了DocPrintJob類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: print

import javax.print.DocPrintJob; //導入依賴的package包/類
@Override
public boolean print(Label label, String codePage) {
  if (psBarCode == null) {
    System.err.println("Barcode printer not found");
    return false;
  }
  try {
    byte[] bytes = label.getCommands().getBytes("cp" + codePage);
    DocPrintJob job = psBarCode.createPrintJob();
    DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    Doc doc = new SimpleDoc(bytes, flavor, null);
    job.print(doc, null);
  } catch (Exception e) {
    e.printStackTrace();
    return false;
  }
  return true;
}
 
開發者ID:unsftn,項目名稱:bisis-v4,代碼行數:19,代碼來源:Printer2.java

示例2: main

import javax.print.DocPrintJob; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:33,代碼來源:PrintSEUmlauts.java

示例3: setupJavaPrint

import javax.print.DocPrintJob; //導入依賴的package包/類
protected void setupJavaPrint() {
    // "install" another default printer
    PrintService psDefault = mock(PrintService.class);
    when(psDefault.getName()).thenReturn("DefaultPrinter");
    when(psDefault.isDocFlavorSupported(any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = mock(PrintServiceLookup.class);
    when(psLookup.getPrintServices()).thenReturn(new PrintService[]{psDefault});
    when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = mock(DocPrintJob.class);
    when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[]{
        MediaTray.TOP,
        MediaTray.MIDDLE,
        MediaTray.BOTTOM
    };
    when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:PrinterPrintTest.java

示例4: out

import javax.print.DocPrintJob; //導入依賴的package包/類
public static boolean out(BufferedImage image) {
	try {
		DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
		PrintRequestAttributeSet requestAttributeSet = new HashPrintRequestAttributeSet();
		requestAttributeSet.add(MediaSizeName.ISO_A4);
		requestAttributeSet.add(new JobName(LSystem.applicationName + LSystem.getTime(), Locale.ENGLISH));
		PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, requestAttributeSet);
		PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
		PrintService service = ServiceUI.printDialog(null, 100, 100, services, defaultService, flavor,
				requestAttributeSet);
		if (service != null) {
			DocPrintJob job = service.createPrintJob();
			SimpleDoc doc = new SimpleDoc(new BufferedImagePrintable(image), flavor, null);
			job.print(doc, requestAttributeSet);
		}
	} catch (Exception e) {
		return false;
	}
	return true;
}
 
開發者ID:cping,項目名稱:RipplePower,代碼行數:21,代碼來源:PrintImageOutput.java

示例5: printZpl

import javax.print.DocPrintJob; //導入依賴的package包/類
/**
 * Function to print code Zpl to local zebra(usb)
 * 
 * @param zpl
 *            code Zpl to print
 * @param ip
 *            ip adress
 * @param port
 *            port
 * @throws ZebraPrintException
 *             if zpl could not be printed
 */
public static void printZpl(String zpl, String printerName) throws ZebraPrintException {
	try {

		PrintService psZebra = null;
		String sPrinterName = null;
		PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

		for (int i = 0; i < services.length; i++) {
			PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
			sPrinterName = ((PrinterName) attr).getValue();
			if (sPrinterName.toLowerCase().indexOf(printerName) >= 0) {
				psZebra = services[i];
				break;
			}
		}

		if (psZebra == null) {
			throw new ZebraPrintNotFoundException("Zebra printer not found : " + printerName);
		}
		DocPrintJob job = psZebra.createPrintJob();

		byte[] by = zpl.getBytes();
		DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
		Doc doc = new SimpleDoc(by, flavor, null);
		job.print(doc, null);

	} catch (PrintException e) {
		throw new ZebraPrintException("Cannot print label on this printer : " + printerName, e);
	}
}
 
開發者ID:w3blogfr,項目名稱:zebra-zpl,代碼行數:43,代碼來源:ZebraUtils.java

示例6: setup

import javax.print.DocPrintJob; //導入依賴的package包/類
@Before
public void setup() {
    PrintService psDefault = Mockito.mock(PrintService.class);
    Mockito.when(psDefault.getName()).thenReturn("DefaultPrinter");
    Mockito.when(psDefault.isDocFlavorSupported(Mockito.any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    PrintServiceLookup psLookup = Mockito.mock(PrintServiceLookup.class);
    Mockito.when(psLookup.getPrintServices()).thenReturn(new PrintService[]{psDefault});
    Mockito.when(psLookup.getDefaultPrintService()).thenReturn(psDefault);
    DocPrintJob docPrintJob = Mockito.mock(DocPrintJob.class);
    Mockito.when(psDefault.createPrintJob()).thenReturn(docPrintJob);
    MediaTray[] trays = new MediaTray[]{
        MediaTray.TOP,
        MediaTray.MIDDLE,
        MediaTray.BOTTOM
    };
    Mockito.when(psDefault.getSupportedAttributeValues(Media.class, null, null)).thenReturn(trays);
    PrintServiceLookup.registerServiceProvider(psLookup);
}
 
開發者ID:wildfly-extras,項目名稱:wildfly-camel,代碼行數:19,代碼來源:PrinterIntegrationTest.java

示例7: createPrintJob

import javax.print.DocPrintJob; //導入依賴的package包/類
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new Win32PrintJob(this);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:Win32PrintService.java

示例8: createPrintJob

import javax.print.DocPrintJob; //導入依賴的package包/類
public DocPrintJob createPrintJob() {
  SecurityManager security = System.getSecurityManager();
  if (security != null) {
    security.checkPrintJobAccess();
  }
    return new UnixPrintJob(this);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:UnixPrintService.java

示例9: createPrintJob

import javax.print.DocPrintJob; //導入依賴的package包/類
public DocPrintJob createPrintJob() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    // REMIND: create IPPPrintJob
    return new UnixPrintJob(this);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:IPPPrintService.java

示例10: createPrintJob

import javax.print.DocPrintJob; //導入依賴的package包/類
@Override
public DocPrintJob createPrintJob(){
    SecurityManager security = System.getSecurityManager();
    if(security != null){
        security.checkPrintJobAccess();
    }
    return new Win32PrintJob(this, peer);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:Win32PrintService.java

示例11: print

import javax.print.DocPrintJob; //導入依賴的package包/類
/**
   *
   * @param path
   * @throws PrintException
   * @throws IOException
   */
  public void print(String path) throws PrintException, IOException {
  String defaultPrinter =lookupDefaultPrintService().getName();
          showMessageDialog(null,"Default printer: " + defaultPrinter);

  PrintService service = lookupDefaultPrintService();
  DocFlavor flavor;
      PrintJobWatcher pjw;
      try (FileInputStream in = new FileInputStream(new File(path))) {
          PrintRequestAttributeSet  pras = new HashPrintRequestAttributeSet();
          pras.add(new Copies(1));
          flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
          Doc doc = new SimpleDoc(in, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
          DocPrintJob job = service.createPrintJob();
          pjw = new PrintJobWatcher(job);
          job.print(doc, pras);
          pjw.waitForDone();
      }

  // send FF to eject the page
  InputStream ff = new ByteArrayInputStream("\f".getBytes());
  Doc docff = new SimpleDoc(ff, flavor, null);
  DocPrintJob jobff = service.createPrintJob();
  pjw = new PrintJobWatcher(jobff);
  jobff.print(docff, null);
  pjw.waitForDone();
}
 
開發者ID:GaneshKandu,項目名稱:MedicalRS,代碼行數:33,代碼來源:PrintBillFile.java

示例12: print

import javax.print.DocPrintJob; //導入依賴的package包/類
/**
 *
 * @param g Graphic class
 * @param pf page format
 * @param page page count
 * @return 1
 * @throws PrinterException
 *
 * This methos print to pdf
 */
@Override
public int print(Graphics g, PageFormat pf, int page) throws
        PrinterException {

    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
    PrintRequestAttributeSet patts = new HashPrintRequestAttributeSet();
    patts.add(Sides.DUPLEX);
    PrintService[] ps = PrintServiceLookup.lookupPrintServices(flavor, patts);
    if (ps.length == 0) {
        //
    }
    //System.out.println("Available printers: " + Arrays.asList(ps));
    PrintService myService = null;
    for (PrintService printService : ps) {
        if (printService.getName().equals("Your printer name")) {
            myService = printService;
            break;
        }
    }
    if (myService == null) {
        //
    }
    try (FileInputStream fis = new FileInputStream(file)) {
        Doc pdfDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
        DocPrintJob printJob = myService.createPrintJob();
        printJob.print(pdfDoc, new HashPrintRequestAttributeSet());
    } catch (Exception e) {
        e.printStackTrace();
        throw new PrinterException("File Not Found!");
    }
    return 1;
}
 
開發者ID:accountingSoftwareCSE343Group4,項目名稱:accounting_Soft,代碼行數:43,代碼來源:Printer.java

示例13: PrintJobAttributeEvent

import javax.print.DocPrintJob; //導入依賴的package包/類
/**
 * Constructs a <code>PrintJobAttributeEvent</code> object.
 *
 * @param source the source of this event
 * @param attributes the attribute changes being reported
 */
public PrintJobAttributeEvent(DocPrintJob source,
                              PrintJobAttributeSet attributes)
{
  super(source);
  this.attributes = attributes;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:13,代碼來源:PrintJobAttributeEvent.java

示例14: print

import javax.print.DocPrintJob; //導入依賴的package包/類
public void print() throws IOException, PrintException {
    
    DocFlavor inputFlavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
    
    // Lookup a print factory to convert from desired input to output.
    StreamPrintServiceFactory[] psfactories =
        StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
            inputFlavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
    if (psfactories.length == 0) {
        System.err.println("Ack! No StreamPrintFactory found for this job!");
    }
    StreamPrintService printService = 
        psfactories[0].getPrintService(new FileOutputStream("demo.ps"));
    PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
    attrs.add(OrientationRequested.LANDSCAPE);
    attrs.add(MediaSizeName.NA_LETTER);
    attrs.add(new Copies(1));
    attrs.add(new JobName(INPUT_FILE_NAME, null));

    InputStream is = getClass().getResourceAsStream(INPUT_FILE_NAME);
    if (is == null) {
        throw new NullPointerException(
            "Input Stream is null: file not found?");
    }
    Doc doc = new SimpleDoc(is, inputFlavor, null);
    
    DocPrintJob printJob = printService.createPrintJob();
    printJob.print(doc, attrs);
}
 
開發者ID:shashanksingh28,項目名稱:code-similarity,代碼行數:30,代碼來源:PrintPostScript.java

示例15: print

import javax.print.DocPrintJob; //導入依賴的package包/類
/** Print a file by name 
 * @throws IOException
 * @throws PrintException 
 */
public void print(String fileName) throws IOException, PrintException {
    System.out.println("PrintServiceDemo.print(): Printing " + fileName);
    DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    //aset.add(MediaSize.NA.LETTER);
    aset.add(MediaSizeName.NA_LETTER);
    //aset.add(new JobName(INPUT_FILE_NAME, null));
    PrintService[] pservices = 
        PrintServiceLookup.lookupPrintServices(flavor, aset);
    int i;
    switch(pservices.length) {
    case 0:
        System.err.println(0);
        JOptionPane.showMessageDialog(PrintServiceDemo.this,
            "Error: No PrintService Found", "Error", 
            JOptionPane.ERROR_MESSAGE);
        return;
    case 1:
        i = 0;    // Only one printer, use it.
        break;
    default:
        i = JOptionPane.showOptionDialog(this, 
            "Pick a printer", "Choice", 
            JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, 
            null, pservices, pservices[0]);
        break;
    }
    DocPrintJob pj = pservices[i].createPrintJob();
    InputStream is = getClass().getResourceAsStream(INPUT_FILE_NAME);
    if (is == null) {
        throw new NullPointerException("Input Stream is null: file not found?");
    }
    Doc doc = new SimpleDoc(is, flavor, null);
    
    pj.print(doc, aset);
}
 
開發者ID:shashanksingh28,項目名稱:code-similarity,代碼行數:41,代碼來源:PrintServiceDemo.java


注:本文中的javax.print.DocPrintJob類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。