Package javax.print

Examples of javax.print.PrintService


  }

  private static PrintService lookupPrintService()
      throws PrintException
  {
    final PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    if (defaultService != null &&
        defaultService.isDocFlavorSupported(DocFlavor.SERVICE_FORMATTED.PAGEABLE))
    {
        return defaultService;
    }
   
    final PrintService printService;
    final PrintService[] services = PrintServiceLookup.lookupPrintServices(
        DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
    if (services.length == 0)
    {
      throw new PrintException
View Full Code Here


    }
    PrintRequestAttributeSet attributes =
        Java14PrintUtil.copyConfiguration(null, report);
    attributes = Java14PrintUtil.copyAuxillaryAttributes(attributes, report);

    final PrintService service = ServiceUI.printDialog
        (null, 50, 50, services, lookupPrintService(),
            DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes);
    if (service == null)
    {
      return false;
    }

    final PrintReportProcessor reportPane = new PrintReportProcessor(report);
    if (progressListener != null)
    {
      reportPane.addReportProgressListener(progressListener);
    }

    try
    {
      reportPane.fireProcessingStarted();

      final DocPrintJob job = service.createPrintJob();
      final SimpleDoc document = new SimpleDoc
          (reportPane, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);

      job.print(document, attributes);
    }
View Full Code Here

    final TypedTableModel tt = new TypedTableModel();
    tt.addColumn("Printer ID", String.class);
    tt.addColumn("Printer Name", String.class);
    for (int i = 0; i < services.length; i++)
    {
      final PrintService service = services[i];
      final PrinterName displayName = service.getAttribute(PrinterName.class);
      if (displayName != null)
      {
        tt.addRow(new Object[]{service.getName(), displayName.getValue()});
      }
      else
      {
        tt.addRow(new Object[]{service.getName(), service.getName()});
      }
    }
    return tt;
  }
View Full Code Here

      StreamPrintServiceFactory[] factories =
        StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
      System.out.println(Arrays.toString(factories));
      if (factories.length > 0) {
        FileOutputStream out = new FileOutputStream(fileName);
        PrintService service = factories[0].getPrintService(out);
        SimpleDoc doc = new SimpleDoc(new Printable() {
          @Override
          public int print(Graphics g, PageFormat pf, int page) {
            if (page >= 1) return Printable.NO_SUCH_PAGE;
            else {
              Graphics2D g2 = (Graphics2D) g;
              g2.translate((pf.getWidth() - pf.getImageableWidth()) / 2,
                     (pf.getHeight() - pf.getImageableHeight()) / 2);
              if ( comp.getWidth() > pf.getImageableWidth() ||
                 comp.getHeight() > pf.getImageableHeight() )
              {
                double sf1 = pf.getImageableWidth() / (comp.getWidth() + 1);
                double sf2 = pf.getImageableHeight() / (comp.getHeight() + 1);
                double s = Math.min(sf1, sf2);
                g2.scale(s, s);
              }

              comp.paint(g);
              return Printable.PAGE_EXISTS;
            }
          }
        }, flavor, null);
        DocPrintJob job = service.createPrintJob();
        PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
        job.print(doc, attributes);
        out.close();
      }
    } else {
View Full Code Here

  public static String[] listPrinters(){
    String[] printerNames = new String[0];
    try {
      PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
      DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
      PrintService printService[] =  PrintServiceLookup.lookupPrintServices(flavor, pras);
      printerNames = new String[printService.length];
      for(int i=0;i<printService.length;i++){
        String name = "Error";
        PrintService service = printService[i];
        if (service != null) {
          name = service.getName();
          if (name == null) {
            name = "Undefined";
          }
        }
        printerNames[i] = name;         
View Full Code Here

    if(currentService == null
       || currentPrinterName == null
       || !printerName.equals(currentPrinterName)){
      PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
      DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
      PrintService printService[] =  PrintServiceLookup.lookupPrintServices(flavor, pras);
      int i = 0;
      String trimemdPrinterName = printerName.trim();
      while ( i<printService.length && !trimemdPrinterName.equalsIgnoreCase(printService[i].getName()) ){
        i++;
      }
View Full Code Here

     * those of the current service and the specified attributes.
     * @since 1.6
     */
    public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {

        PrintService service = getPrintService();
        PageFormat pf = defaultPage();

        if (service == null || attributes == null) {
            return pf;
        }

        Media media = (Media)attributes.get(Media.class);
        MediaPrintableArea mpa =
            (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
        OrientationRequested orientReq =
           (OrientationRequested)attributes.get(OrientationRequested.class);

        if (media == null && mpa == null && orientReq == null) {
           return pf;
        }
        Paper paper = pf.getPaper();

        /* If there's a media but no media printable area, we can try
         * to retrieve the default value for mpa and use that.
         */
        if (mpa == null && media != null &&
            service.isAttributeCategorySupported(MediaPrintableArea.class)) {
            Object mpaVals =
                service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                    null, attributes);
            if (mpaVals instanceof MediaPrintableArea[] &&
                ((MediaPrintableArea[])mpaVals).length > 0) {
                mpa = ((MediaPrintableArea[])mpaVals)[0];
            }
        }

        if (media != null &&
            service.isAttributeValueSupported(media, null, attributes)) {
            if (media instanceof MediaSizeName) {
                MediaSizeName msn = (MediaSizeName)media;
                MediaSize msz = MediaSize.getMediaSizeForName(msn);
                if (msz != null) {
                    double inch = 72.0;
                    double paperWid = msz.getX(MediaSize.INCH) * inch;
                    double paperHgt = msz.getY(MediaSize.INCH) * inch;
                    paper.setSize(paperWid, paperHgt);
                    if (mpa == null) {
                        paper.setImageableArea(inch, inch,
                                               paperWid-2*inch,
                                               paperHgt-2*inch);
                    }
                }
            }
        }

        if (mpa != null &&
            service.isAttributeValueSupported(mpa, null, attributes)) {
            float [] printableArea =
                mpa.getPrintableArea(MediaPrintableArea.INCH);
            for (int i=0; i < printableArea.length; i++) {
                printableArea[i] = printableArea[i]*72.0f;
            }
            paper.setImageableArea(printableArea[0], printableArea[1],
                                   printableArea[2], printableArea[3]);
        }

        if (orientReq != null &&
            service.isAttributeValueSupported(orientReq, null, attributes)) {
            int orient;
            if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
                orient = PageFormat.REVERSE_LANDSCAPE;
            } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
                orient = PageFormat.LANDSCAPE;
View Full Code Here

    private DocPrintJob createDocPrintJob() {
        PrintService[] services = PrintServiceLookup.lookupPrintServices(
                DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
        PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
        PrintService printService = ServiceUI.printDialog(null, 50, 50,
                services, services[0], null, attributes);
        if (printService != null) {
            return printService.createPrintJob();
        } else {
            return null;
        }
    }
View Full Code Here

            reportfields.put("TICKET", ticket);
            reportfields.put("PLACE", ticketext);

            JasperPrint jp = JasperFillManager.fillReport(jr, reportparams, new JRMapArrayDataSource(new Object[] { reportfields } ));
           
            PrintService service = ReportUtils.getPrintService(m_App.getProperties().getProperty("machine.printername"));
           
            JRPrinterAWT300.printPages(jp, 0, jp.getPages().size() - 1, service);
           
        } catch (Exception e) {
            MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotloadreport"), e);
View Full Code Here

    @Override
    public void endReceipt() {

        try {

            PrintService ps;

            if (printservice == null) {
                String[] printers = ReportUtils.getPrintNames();
                if (printers.length == 0) {
                    logger.warning(AppLocal.getIntString("message.noprinters"));
                    ps = null;
                } else {
                    SelectPrinter selectprinter = SelectPrinter.getSelectPrinter(parent, printers);
                    selectprinter.setVisible(true);
                    if (selectprinter.isOK()) {
                        ps = ReportUtils.getPrintService(selectprinter.getPrintService());
                    } else {
                        ps = null;
                    }
                }
            } else {
                ps = printservice;
            }

            if (ps != null)  {

                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(OrientationRequested.PORTRAIT);
                aset.add(new JobName(AppLocal.APP_NAME + " - Document", null));
                aset.add(media);

                DocPrintJob printjob = ps.createPrintJob();
                Doc doc = new SimpleDoc(new PrintableBasicTicket(m_ticketcurrent, imageable_x, imageable_y, imageable_width, imageable_height), DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);

                printjob.print(doc, aset);
            }
View Full Code Here

TOP

Related Classes of javax.print.PrintService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.