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


Java PrintRequestAttributeSet.add方法代码示例

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


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

示例1: printDocument

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的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

示例2: printTest

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的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

示例3: main

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的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

示例4: printWithoutPrintDialog

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
private static void printWithoutPrintDialog() {

        final JTable table = createAuthorTable(42);
        PrintRequestAttributeSet pras
                = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        try {

            boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH,
                    new MessageFormat("Author Table"),
                    new MessageFormat("Page - {0}"),
                    false, pras, false);

            closeFrame();
            if (!printAccepted) {
                throw new RuntimeException("User cancels the printer job!");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:ImageableAreaTest.java

示例5: actionPerformed

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e)
{
    try {
        if (selectedDriver == null)
            return;

        PrintService ps = (PrintService)printers.getSelectedItem();
        PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();

        attr.add(new Copies(1));
        attr.add((Media)ps.getDefaultAttributeValue(Media.class)); // set to default paper from printer
        attr.add(OrientationRequested.LANDSCAPE);

        SimpleDoc doc = new SimpleDoc(activeLabel, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
        ps.createPrintJob().print(doc, attr);
    }  catch (PrintException ex) {
        log.log(Level.SEVERE, "\bBarcode print failed: " + ex.getMessage(), ex);
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:21,代码来源:EntryPanel.java

示例6: addPaperSize

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
private void addPaperSize(PrintRequestAttributeSet aset,
                          int dmIndex, int width, int length) {

    if (aset == null) {
        return;
    }
    MediaSizeName msn =
       ((Win32PrintService)myService).findWin32Media(dmIndex);
    if (msn == null) {
        msn = ((Win32PrintService)myService).
            findMatchingMediaSizeNameMM((float)width, (float)length);
    }

    if (msn != null) {
        aset.add(msn);
    }
}
 
开发者ID:JetBrains,项目名称:jdk8u_jdk,代码行数:18,代码来源:WPrinterJob.java

示例7: printWithoutPrintDialog

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
private static void printWithoutPrintDialog() {

        final JTable table = createAuthorTable(50);
        PrintRequestAttributeSet pras
                = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        try {

            boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH,
                    new MessageFormat("Author Table"),
                    new MessageFormat("Page - {0}"),
                    false, pras, false);

            closeFrame();
            if (!printAccepted) {
                throw new RuntimeException("User cancels the printer job!");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
开发者ID:campolake,项目名称:openjdk9,代码行数:24,代码来源:ImageableAreaTest.java

示例8: print

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
/**
 *
 */
public void print() throws JRException
{
	long start = System.currentTimeMillis();
	PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
	printRequestAttributeSet.add(MediaSizeName.ISO_A4);

	PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
	//printServiceAttributeSet.add(new PrinterName("Epson Stylus 820 ESC/P 2", null));
	//printServiceAttributeSet.add(new PrinterName("hp LaserJet 1320 PCL 6", null));
	//printServiceAttributeSet.add(new PrinterName("PDFCreator", null));
	
	JRPrintServiceExporter exporter = new JRPrintServiceExporter();
	
	exporter.setExporterInput(new SimpleExporterInput("build/reports/PrintServiceReport.jrprint"));
	SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
	configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
	configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
	configuration.setDisplayPageDialog(false);
	configuration.setDisplayPrintDialog(true);
	exporter.setConfiguration(configuration);
	exporter.exportReport();

	System.err.println("Printing time : " + (System.currentTimeMillis() - start));
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:28,代码来源:PrintServiceApp.java

示例9: printTest

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
private static void printTest() {
    PrinterJob pj = PrinterJob.getPrinterJob();
    PageableHandler handler = new PageableHandler();
    pj.setPageable(handler);

    PrintRequestAttributeSet pSet =  new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.COMMON);
    pj.printDialog(pSet);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:PrintDlgPageable.java

示例10: printTest

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
private static void printTest() {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    job.setPrintable(new DlgAttrsBug());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    aset.add(new PageRanges(3,4));
    aset.add(DialogTypeSelection.NATIVE);
    job.printDialog(aset);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:DlgAttrsBug.java

示例11: printWithCustomImageareaSize

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的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

示例12: main

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
public static void main(String args[]) {
    PrinterJob job;

    job = PrinterJob.getPrinterJob();

    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

    // Here you could see the PageFormat with an empty PrintRequestAttributeSet
    PageFormat pf2 = job.getPageFormat(pras);
    System.out.println((pf2.getImageableX() / 72f) + " "
            + (pf2.getImageableY() / 72f) + " "
            + (pf2.getImageableWidth() / 72f) + " "
            + (pf2.getImageableHeight() / 72f)
    );

    // Set left margin to 2.0
    pras.add(new MediaPrintableArea(2.0f,
            (float)(pf2.getImageableY() / 72f),
            (float) ((pf2.getImageableWidth() / 72f) - 1.0f),
            (float) (pf2.getImageableHeight() / 72f),
            MediaPrintableArea.INCH));

    pf2 = job.getPageFormat(pras);
    System.out.println((pf2.getImageableX() / 72f) + " "
            + (pf2.getImageableY() / 72f) + " "
            + (pf2.getImageableWidth() / 72f) + " "
            + (pf2.getImageableHeight() / 72f)
    );

    // check if returned left margin of imageable area is 2.0 as set earlier
    if (pf2.getImageableX() / 72f != 2.0f) {
        throw new RuntimeException("getPageFormat doesn't apply specified "
                + "MediaPrintableArea attribute");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:TestPgfmtSetMPA.java

示例13: main

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
public static void main(String args[]) {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job == null) {
        return;
    }
    PrintRequestAttributeSet pSet =
         new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    job.printDialog(pSet);
    try {
        job.pageDialog(pSet);
    } catch (StackOverflowError e) {
        throw new RuntimeException("StackOverflowError is thrown");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:PageDlgStackOverflowTest.java

示例14: printWorks

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的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:campolake,项目名称:openjdk9,代码行数:34,代码来源:TestUnsupportedResolution.java

示例15: printContent

import javax.print.attribute.PrintRequestAttributeSet; //导入方法依赖的package包/类
public void printContent() {
    printStr = "打印测试内容";// 获取需要打印的目标文本
    if (printStr != null && printStr.length() > 0) // 当打印内容不为空时
    {
        PAGES = 1; // 获取打印总页数
        // 指定打印输出格式
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        // 定位默认的打印服务
        PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
       // PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
       // Toolkit.getDefaultToolkit().getPrintJob
        // 创建打印作业
        PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
        //PrintService service = ServiceUI.printDialog(null, 200, 200, printService, printService , flavor, pras);
        //DocPrintJob job = printService.createPrintJob();
        DocPrintJob job = service.createPrintJob();
        // 设置打印属性
       // PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        // 设置纸张大小,也可以新建MediaSize类来自定义大小
        pras.add(MediaSizeName.ISO_A4);
        DocAttributeSet das = new HashDocAttributeSet();
        // 指定打印内容
        Doc doc = new SimpleDoc(this, flavor, das);
        // 不显示打印对话框,直接进行打印工作
        try {
        
            job.print(doc, pras); // 进行每一页的具体打印操作
        } catch (PrintException pe) {
            pe.printStackTrace();
        }
    } else {
        // 如果打印内容为空时,提示用户打印将取消
        JOptionPane.showConfirmDialog(null,"Sorry, Printer Job is Empty, Print Cancelled!", "Empty", JOptionPane.DEFAULT_OPTION,  JOptionPane.WARNING_MESSAGE);
    }
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:38,代码来源:LocatePrint.java


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