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


Java PrinterJob.print方法代码示例

本文整理汇总了Java中java.awt.print.PrinterJob.print方法的典型用法代码示例。如果您正苦于以下问题:Java PrinterJob.print方法的具体用法?Java PrinterJob.print怎么用?Java PrinterJob.print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.print.PrinterJob的用法示例。


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

示例1: thirdPartyPrintLogic

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
static void thirdPartyPrintLogic(String printerName) throws Exception {
    PrinterJob printerjob = PrinterJob.getPrinterJob();
    printerjob.setCopies(2);
    printerjob.setJobName("myJobName");
    printerjob.setPrintable(new DummyPrintable());
    for (PrintService printService : PrinterJob.lookupPrintServices()) {
        System.out.println("check printer name of service " + printService);
        if (printerName.equals(printService.getName())) {
            System.out.println("correct printer service do print...");
            printerjob.setPrintService(printService);
            printerjob.print();
            break;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:DummyPrintTest.java

示例2: printDocument

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static void printDocument() throws IOException, PrinterException
{	
	
	PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

    pras.add(Sides.TWO_SIDED_SHORT_EDGE);
	PDDocument input = PDDocument.load(new File("Karteikarten.pdf"));
	
	PrinterJob job = PrinterJob.getPrinterJob();
	job.setPageable(new PDFPageable(input));
	if (job.printDialog(pras)) {
	    job.print(pras);
	}
	
}
 
开发者ID:CoffeeCodeSwitzerland,项目名称:Lernkartei_2017,代码行数:16,代码来源:Printer.java

示例3: actionPerformed

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
 * 
 */
public void actionPerformed(ActionEvent e) {
  if (e.getSource() instanceof mxGraphComponent) {
    mxGraphComponent graphComponent = (mxGraphComponent) e.getSource();
    PrinterJob pj = PrinterJob.getPrinterJob();

    if (pj.printDialog()) {
      PageFormat pf = graphComponent.getPageFormat();
      Paper paper = new Paper();
      double margin = 36;
      paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
          paper.getHeight() - margin * 2);
      pf.setPaper(paper);
      pj.setPrintable(graphComponent, pf);

      try {
        pj.print();
      } catch (PrinterException e2) {
        System.out.println(e2);
      }
    }
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:26,代码来源:EditorActions.java

示例4: printTest

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printTest() {
    PrinterJob pj = PrinterJob.getPrinterJob();

    PageFormat pf = pj.defaultPage();
    Paper paper = new Paper();
    double margin = 36; // half inch
    paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
            paper.getHeight() - margin * 2);
    pf.setPaper(paper);

    pj.setPrintable(new PrintTestLexmarkIQ(), pf);
    if (pj.printDialog()) {
        try {
            pj.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:PrintTestLexmarkIQ.java

示例5: printTest

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printTest() {

        MediaTray tray = null;
        //tray = getMediaTray( prservices, "Bypass Tray" );
        tray = getMediaTray( prservices, "Tray 4" );
        PrintRequestAttributeSet atrset = new HashPrintRequestAttributeSet();
        //atrset.add( MediaSizeName.ISO_A4 );
        atrset.add(tray);
        PrinterJob pjob = PrinterJob.getPrinterJob();
        pjob.setPrintable(new TestMediaTraySelection());
        try {
            pjob.print(atrset);
        } catch (PrinterException e) {
            e.printStackTrace();
            fail();
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TestMediaTraySelection.java

示例6: createChartPrintJob

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
 * Creates a print job for the chart.
 */

@Override
public void createChartPrintJob() {

	PrinterJob job = PrinterJob.getPrinterJob();
	PageFormat pf = job.defaultPage();
	PageFormat pf2 = job.pageDialog(pf);
	if (pf2 != pf) {
		job.setPrintable(this, pf2);
		if (job.printDialog()) {
			try {
				job.print();
			} catch (PrinterException e) {
				JOptionPane.showMessageDialog(this, e);
			}
		}
	}

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:AbstractChartPanel.java

示例7: doTest

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:WrongPaperPrintingTest.java

示例8: actionPerformed

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent event) {
    if (event.getSource() == _fillButton) {
        fillPlot();
    }
    else if (event.getSource() == _printButton) {
        PrinterJob job = PrinterJob.getPrinterJob();
        // [email protected]: Get the Page Format and use it.
        PageFormat format = job.pageDialog( job.defaultPage() );
        job.setPrintable(PlotBox.this, format);
        if (job.printDialog()) {
            try {
                job.print();
            } catch (Exception ex) {
                Component ancestor = getTopLevelAncestor();
                JOptionPane.showMessageDialog(ancestor,
                        "Printing failed:\n" + ex.toString(),
                        "Print Error", JOptionPane.WARNING_MESSAGE);
            }
        }
    }
    else if (event.getSource() == _resetButton) {
        resetAxes();
    }
    else if (event.getSource() == _formatButton) {
        PlotFormatter fmt = new PlotFormatter(PlotBox.this);
        fmt.openModal();
    }
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:29,代码来源:PlotBox.java

示例9: printDifferentRowHeight

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printDifferentRowHeight() {
    final JTable table = createAuthorTable(50);
    table.setRowHeight(15, table.getRowHeight(15)+10);
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}"));

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog();
    if (printAccepted) {
        try {
            job.print();
            closeFrame();
        } catch (PrinterException e) {
            throw new RuntimeException(e);
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ImageableAreaTest.java

示例10: createChartPrintJob

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {

    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf) {
        job.setPrintable(this, pf2);
        if (job.printDialog()) {
            try {
                job.print();
            }
            catch (PrinterException e) {
                JOptionPane.showMessageDialog(this, e);
            }
        }
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:ChartPanel.java

示例11: printWithJavaPrintDialog

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printWithJavaPrintDialog() {
    final JTable table = createAuthorTable(42);
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}"));

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog();
    if (printAccepted) {
        try {
            job.print();
            closeFrame();
        } catch (PrinterException e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ImageableAreaTest.java

示例12: printWorksheet

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void printWorksheet() {
	PrinterJob print = PrinterJob.getPrinterJob();
	print.setPrintable(desktop.getSelectedFrame());
	if(print.printDialog(new HashPrintRequestAttributeSet()))
		try { print.print(); }
	catch(PrinterException e) {}
}
 
开发者ID:kristian,项目名称:JDigitalSimulator,代码行数:8,代码来源:Application.java

示例13: printWorks

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void printWorks(String[] args)
{
    PrinterJob job=PrinterJob.getPrinterJob();
    job.setPrintable(this);
    PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet();
    PrinterResolution pr = new PrinterResolution(300, 300, ResolutionSyntax.DPI);
    if (args.length > 0 && (args[0].compareTo("600") == 0)) {
        pr = new PrinterResolution(600, 600, ResolutionSyntax.DPI);
        System.out.println("Adding 600 Dpi attribute");
    } else {
        System.out.println("Adding 300 Dpi attribute");
    }
    PrintService ps = job.getPrintService();
    boolean resolutionSupported = ps.isAttributeValueSupported(pr, null, null);
    System.out.println("Is "+pr+" supported by "+ps+"?    "+resolutionSupported);
    if (resolutionSupported) {
        System.out.println("Resolution is supported.\nTest is not applicable, PASSED");
    }
    settings.add(pr);
    if (args.length > 0 && (args[0].equalsIgnoreCase("fidelity"))) {
        settings.add(Fidelity.FIDELITY_TRUE);
        System.out.println("Adding Fidelity.FIDELITY_TRUE attribute");
   }

   if (job.printDialog(settings))
   {
        try {
            job.print(settings);
        } catch (PrinterException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:TestUnsupportedResolution.java

示例14: printWithCustomImageareaSize

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ImageableAreaTest.java

示例15: actionPerformed

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:bug8023392.java


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