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


Java PrinterJob.getPrinterJob方法代码示例

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


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

示例1: getPageFormat

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public PageFormat getPageFormat() {
    PrinterJob job = PrinterJob.getPrinterJob();

    if (myPageFormat == null) {
        myPageFormat = job.defaultPage();

        // restore
        myPageFormat.setOrientation(round(get(PAGE_ORIENTATION, PageFormat.PORTRAIT)));
        Paper paper = myPageFormat.getPaper();

        if (get(PAPER_WIDTH, null) != null && get(PAPER_HEIGHT, null) != null) {
            paper.setSize(get(PAPER_WIDTH, INCH), get(PAPER_HEIGHT, INCH));
        }
        if (get(AREA_X, null) != null && get(AREA_Y, null) != null && get(AREA_WIDTH, null) != null && get(AREA_HEIGHT, null) != null) {
            paper.setImageableArea(get(AREA_X, INCH), get(AREA_Y, INCH), get(AREA_WIDTH, INCH), get(AREA_HEIGHT, INCH));
        }
        myPageFormat.setPaper(paper);
    }
    return myPageFormat;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Config.java

示例2: 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();
		PageFormat format = pj.pageDialog(graphComponent
				.getPageFormat());

		if (format != null)
		{
			graphComponent.setPageFormat(format);
			graphComponent.zoomAndCenter();
		}
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:21,代码来源:EditorActions.java

示例3: 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

示例4: main

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:PageDlgApp.java

示例5: createChartPrintJob

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {
    //FIXME try to replace swing print stuff by swt
    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) {
                MessageBox messageBox = new MessageBox( 
                        canvas.getShell(), SWT.OK | SWT.ICON_ERROR );
                messageBox.setMessage( e.getMessage() );
                messageBox.open();
            }
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:ChartComposite.java

示例6: main

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:PrintCrashTest.java

示例7: main

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Page Dialog will be shown.",
                "Change top(in) margin value from 1.0 to 2.0",
                "Then select OK."
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    PrinterJob pj = PrinterJob.getPrinterJob();
    try {
        HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        PageFormat pf;
        pf = pj.pageDialog(aset);
        double left = pf.getImageableX();
        double top = pf.getImageableY();
        System.out.println("pageDialog - left/top from pageFormat: " + left / 72
                + " " + top / 72);
        System.out.println("pageDialog - left/top from attribute set: "
                + getPrintableXFromASet(aset) + " "
                + getPrintableYFromASet(aset));
        if (top / 72 != 2.0f || getPrintableYFromASet(aset) != 2.0f) {
            throw new RuntimeException("Top margin value not updated");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:PageDialogMarginTest.java

示例8: PolylinePrintingTest

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public PolylinePrintingTest() throws PrinterException {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    Paper p = pf.getPaper();
    p.setImageableArea(0,0,p.getWidth(), p.getHeight());
    pf.setPaper(p);
    job.setPrintable(this, pf);
    if (job.printDialog()) {
        job.print();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:PolylinePrintingTest.java

示例9: actionPerformed

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

示例10: initialize

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private void initialize(byte[] pdfContent, String jobName,String nomeImpressora) throws IOException, PrinterException {
    ByteBuffer bb = ByteBuffer.wrap(pdfContent);

    PDFFile pdfFile = new PDFFile(bb);
    PDFPrintPage pages = new PDFPrintPage(pdfFile);

    PrintService[] pservices = PrinterJob.lookupPrintServices();

    System.out.println(pservices.length);
    if (pservices.length > 0) {
        for (PrintService ps : pservices) {
            System.out.println("Impressora Encontrada: " + ps.getName());

            if (ps.getName().contains(nomeImpressora)) {
                System.out.println("Impressora Selecionada: " + nomeImpressora);
                impressora = ps;
                break;
            }
        }
    }
    if (impressora != null) {
        pjob = PrinterJob.getPrinterJob();
        pjob.setPrintService(impressora);

        PageFormat pf = PrinterJob.getPrinterJob().defaultPage();

        pjob.setJobName(jobName);
        Book book = new Book();
        book.append(pages, pf, pdfFile.getNumPages());
        pjob.setPageable(book);

      
        Paper paper = new Paper();
        paper.setSize(getWidth, getHeight);
        paper.setImageableArea(margin, (int) margin / 4, getWidth - margin * 2, getHeight - margin * 2);
        //paper.setImageableArea(margin,margin, paper.getWidth()-margin*2,paper.getHeight()-margin*2);
        pf.setOrientation(orientacao);
        pf.setPaper(paper);
    }
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:41,代码来源:PrintPdf.java

示例11: print

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void print() {
  PrinterJob printJob = PrinterJob.getPrinterJob();
  printJob.setPrintable((g, format, page) -> {
    if (page > 0) {
      return Printable.NO_SUCH_PAGE;
    }
    // get the bounds of the component
    Rectangle drawingArea = getDrawingArea();
    double cHeight = drawingArea.getSize().getHeight();
    double cWidth = drawingArea.getSize().getWidth();
    // get the bounds of the printable area
    double pHeight = format.getImageableHeight();
    double pWidth = format.getImageableWidth();
    double pXStart = format.getImageableX();
    double pYStart = format.getImageableY();
    //find ratio
    double xRatio = pWidth / cWidth;
    double yRatio = pHeight / cHeight;
    Graphics2D g2d = (Graphics2D) g;
    //translate and scale accordingly
    g2d.translate(pXStart, pYStart);
    g2d.scale(xRatio, yRatio);
    paintDrawing(g2d, drawingArea.x, drawingArea.y);
    return Printable.PAGE_EXISTS;
  });
  if (printJob.printDialog()) {
    try {
      printJob.print();
    } catch (PrinterException e) {
      UIUtility.error(e.getMessage());
    }
  }
}
 
开发者ID:onprom,项目名称:onprom,代码行数:34,代码来源:UMLDiagramPanel.java

示例12: main

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:PrintDialog.java

示例13: showPrintDialog

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private void showPrintDialog() {
  PrinterJob printJob = PrinterJob.getPrinterJob();
  printJob.setPrintable(this);
  PrintRequestAttributeSet printRequestAttrSet =
    new HashPrintRequestAttributeSet();
  printJob.printDialog(printRequestAttrSet);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:PrinterJobDialogBugDemo.java

示例14: 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

示例15: printTest

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static void printTest() {
    printJob = PrinterJob.getPrinterJob();
    System.out.println(" -=- Starting printing #1 -=-");
    print();
    System.out.println(" -=- Starting printing #2 -=-");
    print();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:PrintDlgSelectionAttribTest.java


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