当前位置: 首页>>代码示例>>Java>>正文


Java Doc类代码示例

本文整理汇总了Java中javax.print.Doc的典型用法代码示例。如果您正苦于以下问题:Java Doc类的具体用法?Java Doc怎么用?Java Doc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Doc类属于javax.print包,在下文中一共展示了Doc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: print

import javax.print.Doc; //导入依赖的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: print

import javax.print.Doc; //导入依赖的package包/类
public void print(final Doc doc, final PrintRequestAttributeSet attributes)
                throws PrintException {
    synchronized (lock) {
        if (printer != null) {
            throw new PrintException("Printer is busy"); //$NON-NLS-1$
        } else {
            final DocFlavor flavor = doc.getDocFlavor();

            if ((flavor == null) || !service.isDocFlavorSupported(flavor)) {
                throw new PrintException("Doc flavor is not supported"); //$NON-NLS-1$
            }

            printer = new Printer(doc, attributes);
            printer.print();
        }
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:WinPrintJob.java

示例3: testVerifyAttributeCategory3

import javax.print.Doc; //导入依赖的package包/类
public final void testVerifyAttributeCategory3() {

        //fails in "some" invironment
        //see AttributeSetUtilities, line 337-339

        try {
            AttributeSetUtilities.
                verifyAttributeCategory(SimpleDoc.class, Doc.class);
            fail("method doesn't throw ClassCastException if object " +
                    "is a Class that implements interfaceName but " +
                        "interfaceName is not a class that implements " +
                            "interface Attribute");
        } catch (ClassCastException e) {
            //System.out.println("testVerifyAttributeCategory3 - " + e.toString());
        }

    }
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:AttributeSetUtilitiesTest.java

示例4: printZpl

import javax.print.Doc; //导入依赖的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

示例5: testVerifyAttributeCategory3

import javax.print.Doc; //导入依赖的package包/类
public final void testVerifyAttributeCategory3() {

        //fails in "some" invironment
        //see AttributeSetUtilities, line 337-339

        try {
            AttributeSetUtilities.
                verifyAttributeCategory(SimpleDoc.class, Doc.class);
            fail("metod doesn't throw ClassCastException if object " +
                    "is a Class that implements interfaceName but " +
                        "interfaceName is not a class that implements " +
                            "interface Attribute");
        } catch (ClassCastException e) {
            //System.out.println("testVerifyAttributeCategory3 - " + e.toString());
        }

    }
 
开发者ID:freeVM,项目名称:freeVM,代码行数:18,代码来源:AttributeSetUtilitiesTest.java

示例6: print

import javax.print.Doc; //导入依赖的package包/类
@Override
public void print(Doc doc,
                  PrintRequestAttributeSet printRequestAttributeSet)
      throws PrintException {
    System.out.println("job name: " + printRequestAttributeSet.get(JobName.class));
    System.out.println("copies: " + printRequestAttributeSet.get(Copies.class));
    if(printRequestAttributeSet.get(JobName.class) == null ||
        printRequestAttributeSet.get(Copies.class) == null) {
        throw new RuntimeException("Copies and JobName is not passed correctly");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:DummyPrintTest.java

示例7: print

import javax.print.Doc; //导入依赖的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

示例8: print

import javax.print.Doc; //导入依赖的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

示例9: print

import javax.print.Doc; //导入依赖的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

示例10: print

import javax.print.Doc; //导入依赖的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

示例11: print

import javax.print.Doc; //导入依赖的package包/类
public void print(Doc doc, int copies, boolean sendToPrinter, String mimeType, String jobName) throws PrintException {
    LOG.trace("Print Service: " + this.printService.getName());
    LOG.trace("About to print " + copies + " copy(s)");
    
    for (int i = 0; i < copies; i++) {
        if (!sendToPrinter) {
            LOG.debug("Print flag is set to false. This job will not be printed until this setting remains in effect."
                    + " Please set the flag to true or remove the setting.");

            File file;
            if (mimeType.equalsIgnoreCase("GIF") || mimeType.equalsIgnoreCase("RENDERABLE_IMAGE")) {
                file = new File("./target/TestPrintJobNo" + i + "_" + UUID.randomUUID() + ".gif");
            } else if (mimeType.equalsIgnoreCase("JPEG")) {
                file = new File("./target/TestPrintJobNo" + i + "_" + UUID.randomUUID() + ".jpeg");
            } else if (mimeType.equalsIgnoreCase("PDF")) {
                file = new File("./target/TestPrintJobNo" + i + "_" + UUID.randomUUID() + ".pdf");
            } else {
                file = new File("./target/TestPrintJobNo" + i + "_" + UUID.randomUUID() + ".txt");
            }

            LOG.debug("Writing print job to file: " + file.getAbsolutePath());
            try {
                InputStream in = doc.getStreamForBytes();
                FileOutputStream fos = new FileOutputStream(file);
                IOHelper.copyAndCloseInput(in, fos);
                IOHelper.close(fos);
            } catch (Exception e) {
                throw new PrintException("Error writing Document to the target file " + file.getAbsolutePath());
            }    
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Issuing Job {} to Printer: {}", i, this.printService.getName());
            }
            print(doc, jobName);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:PrinterOperations.java

示例12: printerNameTest

import javax.print.Doc; //导入依赖的package包/类
@Test
public void printerNameTest() throws Exception {
    if (isAwtHeadless()) {
        return;
    }
    // setup javax.print 
    PrintService ps1 = mock(PrintService.class);
    when(ps1.getName()).thenReturn("MyPrinter\\\\remote\\printer1");
    when(ps1.isDocFlavorSupported(any(DocFlavor.class))).thenReturn(Boolean.TRUE);
    boolean res1 = PrintServiceLookup.registerService(ps1);
    assertTrue("The Remote PrintService #1 should be registered.", res1);
    DocPrintJob job1 = mock(DocPrintJob.class);
    when(ps1.createPrintJob()).thenReturn(job1);

    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start1").to("lpr://remote/printer1?sendToPrinter=true");
        }
    });
    context.start();

    template.sendBody("direct:start1", "Hello Printer 1");

    context.stop();

    verify(job1, times(1)).print(any(Doc.class), any(PrintRequestAttributeSet.class));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:PrinterPrintTest.java

示例13: printPrintable

import javax.print.Doc; //导入依赖的package包/类
private void printPrintable(final Doc doc,
                final PrintRequestAttributeSet attributes)
                throws PrintException {
    final long pdc = WinPrinterFactory.getPrinterDC(
                    service.printerName, service.getPrinterProps()
                                    .getStructPtr());
    final AttributeSet docAttrs = doc.getAttributes();
    final Printable printable = castDoc(doc, Printable.class);
    final PageFormat format = getPageFormat(docAttrs, attributes);
    final PageRanges ranges = getAttribute(PageRanges.class, docAttrs,
                    attributes);
    int res = Printable.PAGE_EXISTS;

    try {
        startJob(pdc, getDocName(printable, docAttrs, attributes),
                        getDestinationPath(attributes));

        for (int i = 0; res == Printable.PAGE_EXISTS; i++) {
            if ((ranges != null) && !ranges.contains(i)) {
                continue;
            }

            res = printPrintable(printable, pdc, format, i);
        }

        endJob(pdc);
    } finally {
        WinPrinterFactory.releasePrinterDC(pdc);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:WinPrintJob.java

示例14: printImage

import javax.print.Doc; //导入依赖的package包/类
private void printImage(final Image img, final Doc doc,
                final PrintRequestAttributeSet attributes)
                throws PrintException {
    final PageFormat format = getPageFormat(attributes);
    final long pdc = WinPrinterFactory.getPrinterDC(
                    service.printerName, service.getPrinterProps()
                                    .getStructPtr());
    final double xRes = WinPrinterFactory.getPixelsPerInchX(pdc) / 72;
    final double yRes = WinPrinterFactory.getPixelsPerInchY(pdc) / 72;
    final Graphics2D g2d = new WinGDIPGraphics2D(pdc, (char) 2,
                    (int) (format.getWidth() * xRes), (int) (format
                                    .getHeight() * yRes));

    try {
        startJob(pdc, getDocName(img, attributes),
                        getDestinationPath(attributes));
        WinPrinterFactory.startPage(pdc);
        g2d.drawImage(img, (int) (format.getImageableX() * xRes),
                        (int) (format.getImageableY() * yRes),
                        (int) (format.getImageableWidth() * xRes),
                        (int) (format.getImageableHeight() * yRes),
                        Color.WHITE, null);
        WinPrinterFactory.endPage(pdc);
        endJob(pdc);
    } finally {
        WinPrinterFactory.releasePrinterDC(pdc);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:WinPrintJob.java

示例15: castDoc

import javax.print.Doc; //导入依赖的package包/类
private <T> T castDoc(final Doc doc, final Class<T> c)
                throws PrintException {
    try {
        return c.cast(doc.getPrintData());
    } catch (final IOException ex) {
        throw new PrintException(ex);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:9,代码来源:WinPrintJob.java


注:本文中的javax.print.Doc类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。