Java 类javax.print.attribute.HashPrintRequestAttributeSet 实例源码

项目:Lernkartei_2017    文件:Printer.java   
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);
    }

}
项目:OpenDA    文件:PlotFrame.java   
/** Print using the cross platform dialog.
 *  FIXME: this dialog is slow and is often hidden
 *  behind other windows.  However, it does honor
 *  the user's choice of portrait vs. landscape
 */
protected void _printCrossPlatform() {
    // Build a set of attributes
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(plot);
    if (job.printDialog(aset)) {
        try {
            job.print(aset);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    "Printing failed:\n" + ex.toString(),
                    "Print Error", JOptionPane.WARNING_MESSAGE);
        }
    }
}
项目:jdk8u-jdk    文件:RasterPrinterJob.java   
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
项目:jdk8u-jdk    文件:ImageableAreaTest.java   
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);
        }
    }
项目:openjdk-jdk10    文件:RasterPrinterJob.java   
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
项目:openjdk-jdk10    文件:ImageableAreaTest.java   
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);
        }
    }
项目:openjdk-jdk10    文件:WrongPaperPrintingTest.java   
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);
        }
    }
}
项目:openjdk-jdk10    文件:PrintDialogCancel.java   
private static void init()
{
  //*** Create instructions for the user here ***

  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",
   };
  Sysout.createDialog( );
  Sysout.printInstructions( instructions );

  PrinterJob pjob = PrinterJob.getPrinterJob();
  boolean rv = pjob.printDialog(new HashPrintRequestAttributeSet());
  if (rv) {
      throw new RuntimeException("User pressed cancel, but true returned");
  }
}
项目:openjdk-jdk10    文件:PageDlgApp.java   
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");
        }
    }
项目:openjdk-jdk10    文件:PrintAttributeUpdateTest.java   
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
项目:openjdk-jdk10    文件:TestMediaTraySelection.java   
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();
        }
    }
项目:openjdk-jdk10    文件:ServiceDlgPageRangeTest.java   
/**
 * Starts the application.
 */
public static void printTest() {

    System.out.println("\nDefault print service: " +
                          PrintServiceLookup.lookupDefaultPrintService());
    System.out.println("is flavor: "+flavor+" supported? "+
                                 services[0].isDocFlavorSupported(flavor));
    System.out.println("is Page Ranges category supported? "+
               services[0].isAttributeCategorySupported(PageRanges.class));
    System.out.println("is PageRanges[2] value supported ? "+
               services[0].isAttributeValueSupported(
                                         new PageRanges(2), flavor, null));

    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    //prSet.add(new PageRanges(2));
    PrintService selService = ServiceUI.printDialog(null, 200, 200,
                                      services, services[0], flavor, prSet);

    System.out.println("\nSelected Values\n");
    Attribute attr[] = prSet.toArray();
    for (int x = 0; x < attr.length; x ++) {
        System.out.println("Attribute: " + attr[x].getName() +
                                                    " Value: " + attr[x]);
    }
}
项目:brModelo    文件:PrintControler.java   
public void print() {
    getPrintJob().setPrintable(this, getPage());

    boolean res;
    PrintRequestAttributeSet attr_set
            = new HashPrintRequestAttributeSet();
    if (page_range.x == 0) {
        res = getPrintJob().printDialog();
    } else {
        PrintRequestAttributeSet attr_set2
                = new HashPrintRequestAttributeSet();
        attr_set2.add(new PageRanges(page_range.x, page_range.y));
        res = getPrintJob().printDialog(attr_set2);
    }
    if (res) {
        try {
            getPrintJob().print(attr_set);
        } catch (PrinterException pe) {
            System.out.println("Error printing: " + pe);
        }
        //page = getPrintJob().getPageFormat(null);
    }

}
项目:scorekeeperfrontend    文件:EntryPanel.java   
@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);
    }
}
项目:openjdk9    文件:ImageableAreaTest.java   
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);
        }
    }
项目:openjdk9    文件:PrintDialogCancel.java   
private static void init()
{
  //*** Create instructions for the user here ***

  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",
   };
  Sysout.createDialog( );
  Sysout.printInstructions( instructions );

  PrinterJob pjob = PrinterJob.getPrinterJob();
  boolean rv = pjob.printDialog(new HashPrintRequestAttributeSet());
  if (rv) {
      throw new RuntimeException("User pressed cancel, but true returned");
  }
}
项目:openjdk9    文件:PageDlgApp.java   
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");
        }
    }
项目:openjdk9    文件:PrintAttributeUpdateTest.java   
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
项目:spring-boot    文件:PrintTest.java   
private void printText2Action()
{
    printStr = area.getText().trim();
    if(printStr != null && printStr.length() > 0)
    {
        PAGES = getPagesCount(printStr);
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
        DocPrintJob job = printService.createPrintJob();
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        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", -1, 2);
    }
}
项目:jGAF    文件:ComponentPrintManagerAction.java   
public void actionPerformed(ActionEvent event) {
  if (_compo == null)
    return;
  try {
    PrinterJob pj = PrinterJob.getPrinterJob();
    PageFormat mPageFormat = pj.defaultPage();
    ComponentPrintable cp = new ComponentPrintable(_compo);
    pj.setPrintable(cp, mPageFormat);
    HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
    if (pj.printDialog(attr)) {
      pj.print(attr);
    }
  } catch (PrinterException e) {
    EZLogger.warn("Unable to print: " + e);
  }
}
项目:jasperreports    文件:PrintServiceApp.java   
/**
 *
 */
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));
}
项目:erp    文件:Funcoes.java   
public static void setImpAtrib(PrintRequestAttributeSet p) {
    HashPrintRequestAttributeSet pra = ( HashPrintRequestAttributeSet ) p;
    File fArq = new File("impres.cfg");
    try {
        if (!fArq.exists())
            if (!fArq.createNewFile())
                return;
        FileOutputStream foArq = new FileOutputStream(fArq);
        ObjectOutputStream obj = new ObjectOutputStream(foArq);
        obj.writeObject(pra);
        obj.flush();
        foArq.close();
    }
    catch (IOException err) {
        err.printStackTrace();
    }
}
项目:jdk8u_jdk    文件:ImageableAreaTest.java   
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);
        }
    }
项目:jdk8u_jdk    文件:PageDlgApp.java   
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");
        }
    }
项目:jdk8u_jdk    文件:PrintAttributeUpdateTest.java   
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
项目:lookaside_java-1.8.0-openjdk    文件:ImageableAreaTest.java   
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);
        }
    }
项目:Maxent    文件:PlotFrame.java   
/** Print using the cross platform dialog.
 *  FIXME: this dialog is slow and is often hidden
 *  behind other windows.  However, it does honor
 *  the user's choice of portrait vs. landscape
 */
protected void _printCrossPlatform() {
    // Build a set of attributes
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(plot);

    if (job.printDialog(aset)) {
        try {
            job.print(aset);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    "Printing failed:\n" + ex.toString(), "Print Error",
                    JOptionPane.WARNING_MESSAGE);
        }
    }
}
项目:Camel    文件:PrinterProducer.java   
private PrintRequestAttributeSet assignPrintAttributes() throws PrintException {
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    if (config.getCopies() >= 1) {
        printRequestAttributeSet.add(new Copies(config.getCopies()));
    } else {
        throw new PrintException("Number of print copies should be greater than zero");
    }
    printRequestAttributeSet.add(config.getMediaSizeName());
    printRequestAttributeSet.add(config.getInternalSides());
    printRequestAttributeSet.add(config.getInternalOrientation());

    if (config.getMediaTray() != null) {
        MediaTray mediaTray = resolveMediaTray(config.getMediaTray());

        if (mediaTray == null) {
            throw new PrintException("mediatray not found " + config.getMediaTray());
        }

        printRequestAttributeSet.add(mediaTray);
    }

    return printRequestAttributeSet;
}
项目:metasfresh    文件:CPaper.java   
/**
 *  Return Print Request Attributes
 *  @return PrintRequestAttributeSet
 */
public PrintRequestAttributeSet getPrintRequestAttributeSet()
{
    PrintRequestAttributeSet pratts = new HashPrintRequestAttributeSet();
    //  media-printable-area = (25.4,25.4)->(165.1,228.6)mm - class javax.print.attribute.standard.MediaPrintableArea
    pratts.add(getMediaPrintableArea());
    //  orientation-requested = landscape - class javax.print.attribute.standard.OrientationRequested
    if (isLandscape())
        pratts.add(OrientationRequested.LANDSCAPE);
    else
        pratts.add(OrientationRequested.PORTRAIT);
    //  media = na-legal
    //Commented Lines By AA Goodwill: Custom Paper Support 
    //pratts.add(getMediaSizeName());
    //End Of AA Goodwill

    return pratts;
}
项目:metasfresh    文件:PrintUtil.java   
/**
 *  Print (async)
 *  @param printerName optional printer name
 *  @param jobName optional printer job name
 *  @param pageable pageable
 *  @param copies number of copies
 *  @param withDialog if true, shows printer dialog
 */
static public void print (Pageable pageable, String printerName, String jobName,
    int copies, boolean withDialog)
{
    if (pageable == null)
        return;
    String name = "Adempiere_";
    if (jobName != null)
        name += jobName;
    //
    PrinterJob job = CPrinter.getPrinterJob(printerName);
    job.setJobName (name);
    job.setPageable (pageable);
    //  Attributes
    HashPrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
    prats.add(new Copies(copies));
    //  Set Orientation
    if (pageable.getPageFormat(0).getOrientation() == PageFormat.PORTRAIT)
        prats.add(OrientationRequested.PORTRAIT);
    else
        prats.add(OrientationRequested.LANDSCAPE);
    prats.add(new JobName(name, Language.getLoginLanguage().getLocale()));
    prats.add(getJobPriority(pageable.getNumberOfPages(), copies, withDialog));
    //
    print (job, prats, withDialog, false);
}
项目:fil_project_mgmt_app_v2    文件:ViewProjectParticipants.java   
private void printInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printInfoButtonActionPerformed
    // TODO add your handling code here:
    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat preformat = pjob.defaultPage();
    preformat.setOrientation(PageFormat.PORTRAIT);
    PageFormat postformat = pjob.pageDialog(preformat);
    //If user does not hit cancel then print.
    if (preformat != postformat) {
        //Set print component
        pjob.setPrintable(new Printer(bottomPanel), postformat);
        if (pjob.printDialog()) {
            try {
                PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
                set.add(OrientationRequested.PORTRAIT);
                //pjob.print();
                table.print(JTable.PrintMode.FIT_WIDTH, header, null, false, set, false);
            } catch (PrinterException ex) {
                Logger.getLogger(EditProjectParticipants.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
项目:RipplePower    文件:PrintImageOutput.java   
public static boolean out(BufferedImage image) {
    try {
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintRequestAttributeSet requestAttributeSet = new HashPrintRequestAttributeSet();
        requestAttributeSet.add(MediaSizeName.ISO_A4);
        requestAttributeSet.add(new JobName(LSystem.applicationName + LSystem.getTime(), Locale.ENGLISH));
        PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, requestAttributeSet);
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        PrintService service = ServiceUI.printDialog(null, 100, 100, services, defaultService, flavor,
                requestAttributeSet);
        if (service != null) {
            DocPrintJob job = service.createPrintJob();
            SimpleDoc doc = new SimpleDoc(new BufferedImagePrintable(image), flavor, null);
            job.print(doc, requestAttributeSet);
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
项目:cn1    文件:ServiceUIDialog.java   
private int pageSetup(PrintService aService, 
                      PrintRequestAttributeSet requestAttrs) 
{
    myService = (aService == null)  
            ? PrintServiceLookup.lookupDefaultPrintService() 
            : aService;

    if ((requestAttrs == null) || (aService == null)) {
        return SETUP_ERROR;
    }

    attrs = requestAttrs;
    newAttrs = new HashPrintRequestAttributeSet(attrs);
    myService = aService;

    prepareDialog();        // prepare dialog
    fillPageSetupFields();  // Initialize dialog fields
    firstUse = false;
    return SETUP_OK;
}
项目:cn1    文件:PSPrinterJob.java   
protected PrintRequestAttributeSet updateMediaAndMarginsIfNeeded(
        PrintRequestAttributeSet newAttrs) {

    /* create copy of this.attrs*/
    PrintRequestAttributeSet sum = 
            new HashPrintRequestAttributeSet(this.attrs);

    /* remove MediaMargins and MediaPrintableArea attributes from the copy
       of job attributes if newAttrs contains  MediaMargins or 
       PrintableArea */
    if (newAttrs.containsKey(MediaPrintableArea.class)
                || attrs.containsKey(MediaMargins.class)) {
        sum.remove(MediaPrintableArea.class);
        sum.remove(MediaMargins.class);
    }

    sum.addAll(newAttrs);
    return sum;
}
项目:cn1    文件:PrinterJobImpl.java   
private PrintRequestAttributeSet mergeAttrs(
                final PrintRequestAttributeSet dest) {
    if (dest == attributes) {
        return attributes;
    }

    final PrintRequestAttributeSet attrs = (dest != null) ? dest
                    : new HashPrintRequestAttributeSet();

    for (Attribute attr : attributes.toArray()) {
        if ((attr != null) && !attrs.containsKey(attr.getCategory())) {
            attrs.add(attr);
        }
    }
    return attrs;
}
项目:icepdf    文件:PrintHelper.java   
/**
 * Creates a new <code>PrintHelper</code> instance using the specified
 * doc and print attribute sets.  This constructor offers the most flexibility
 * as it allows the attributes sets to be pre configured.  This method
 * should only be used by advanced users.
 *
 * @param container                parent container uses to center print dialog.
 * @param pageTree                 document page tree.
 * @param userRotation             rotation of view
 * @param docAttributeSet          MediaSizeName constant of paper size to print to.
 * @param printRequestAttributeSet quality of the print job, draft, quality etc.
 */
public PrintHelper(Container container, PageTree pageTree,
                   float userRotation,
                   HashDocAttributeSet docAttributeSet,
                   HashPrintRequestAttributeSet printRequestAttributeSet) {
    this.container = container;
    this.pageTree = pageTree;
    this.userRotation = userRotation;
    // blindly assign doc and print attribute sets.
    this.docAttributeSet = docAttributeSet;
    this.printRequestAttributeSet = printRequestAttributeSet;
    // find available printers
    services = lookForPrintServices();
    // default setup, all pages, shrink to fit and no dialog.
    setupPrintService(0, this.pageTree.getNumberOfPages(), 1, true, false);
}
项目:icepdf    文件:PrintHelper.java   
/**
 * Creates a new <code>PrintHelper</code> instance using the specified
 * doc and print attribute sets.  This constructor offers the most flexibility
 * as it allows the attributes sets to be pre configured.  This method
 * should only be used by advanced users.
 *
 * @param container                parent container uses to center print dialog.
 * @param pageTree                 document page tree.
 * @param userRotation             rotation of view
 * @param docAttributeSet          MediaSizeName constant of paper size to print to.
 * @param printRequestAttributeSet quality of the print job, draft, quality etc.
 */
public PrintHelper(Container container, PageTree pageTree,
                   float userRotation,
                   HashDocAttributeSet docAttributeSet,
                   HashPrintRequestAttributeSet printRequestAttributeSet) {
    this.container = container;
    this.pageTree = pageTree;
    this.userRotation = userRotation;
    // blindly assign doc and print attribute sets.
    this.docAttributeSet = docAttributeSet;
    this.printRequestAttributeSet = printRequestAttributeSet;
    // find available printers
    services = lookForPrintServices();
    // default setup, all pages, shrink to fit and no dialog.
    setupPrintService(0, this.pageTree.getNumberOfPages(), 1, true, false);
}
项目:birt    文件:PrintUtility.java   
/**
 * Find all the printer resources on the server
 * 
 * @return
 */
public static List findPrinters( )
{
    List printers = new ArrayList( );

    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet( );
    DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(
            flavor, pras );
    if ( printServices != null )
    {
        for ( int i = 0; i < printServices.length; i++ )
        {
            PrintService service = printServices[i];
            printers.add( createPrinter( service ) );
        }
    }

    return printers;
}