當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。