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

            PrintService[] services = PrinterJob.lookupPrintServices();
            if (services.length < 1) {
                System.err.println(messageWriter.print0args("noPrinter"));
                return;
            }
            PrintService ps = null;
            if (command.length() > 14) {
                String printerName = command.substring(15);
                for (int i = 0; i < services.length; ++i) {
                    if (services[i].getName().equals(printerName)) {
                        ps = services[i];
View Full Code Here

    case PRINTER_MODE:
      PrintService[] services = PrinterJob.lookupPrintServices();
      if (services.length<1) {
        throw new PrintException("noPrinter", null);
      }
      PrintService ps = null;
      if(dest!=null){
        for (int i=0; i<services.length; ++i) {
          if (services[i].getName().equals(dest)) {
            ps = services[i];
            break;
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

            // bring up a dialog.
            PrintService[] services = PrintServiceLookup.lookupPrintServices(messageFormat, null);

            PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
            PrintService service =  ServiceUI.printDialog(null, 50, 50,
                                                          services,
                                                          PrintServiceLookup.lookupDefaultPrintService(),
                                                          messageFormat,
                                                          attributes);

            if (service != null) {
              final PrintRequestAttributeSet final_attributes = attributes;

              final Doc myDoc = new SimpleDoc(messagePrinter, messageFormat, null);

              final DocPrintJob final_job = service.createPrintJob();

              final MessagePrinterDisplay mpd = new MessagePrinterDisplay(messagePrinter, final_job, final_source);

              final_job.addPrintJobListener(mpd);
View Full Code Here

                }
            }

            Doc myDoc = new SimpleDoc(bais, psInFormat, docAttributeSet);

            PrintService printer = null;

            // lookup the print service for the supplied printer name
            String printerName = (String) serviceContext.remove("printerName");
            if (UtilValidate.isNotEmpty(printerName)) {

                PrintServiceAttributeSet printServiceAttributes = new HashPrintServiceAttributeSet();
                printServiceAttributes.add(new PrinterName(printerName, locale));

                PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, printServiceAttributes);
                if (printServices.length > 0) {
                    printer = printServices[0];
                    Debug.logInfo("Using printer: " + printer.getName(), module);
                    if (!printer.isDocFlavorSupported(psInFormat)) {
                        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPrinterNotSupportDocFlavorFormat", UtilMisc.toMap("psInFormat", psInFormat, "printerName", printer.getName()), locale));
                    }
                }
                if (printer == null) {
                    return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPrinterNotFound", UtilMisc.toMap("printerName", printerName), locale));
                }

            } else {

                // if no printer name was supplied, try to get the default printer
                printer = PrintServiceLookup.lookupDefaultPrintService();
                if (printer != null) {
                    Debug.logInfo("No printer name supplied, using default printer: " + printer.getName(), module);
                }
            }

            if (printer == null) {
                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPrinterNotAvailable", locale));
            }


            PrintRequestAttributeSet praset = new HashPrintRequestAttributeSet();
            List<Object> printRequestAttributes = UtilGenerics.checkList(serviceContext.remove("printRequestAttributes"));
            if (UtilValidate.isNotEmpty(printRequestAttributes)) {
                for (Object pra : printRequestAttributes) {
                    Debug.logInfo("Adding PrintRequestAttribute: " + pra, module);
                    praset.add((PrintRequestAttribute) pra);
                }
            }
            DocPrintJob job = printer.createPrintJob();
            job.print(myDoc, praset);
        } catch (Exception e) {
            Debug.logError(e, "Error rendering [" + contentType + "]: " + e.toString(), module);
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentRenderingError", UtilMisc.toMap("contentType", contentType, "errorString", e.toString()), locale));
        }
View Full Code Here

     * Tests that if this attribute set does not support the add() operation
     * UnmodifiableSetException is thrown.
     */
    public final void testAdd2() {

        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
        if (service != null) {
            PrintServiceAttributeSet psaset = service.getAttributes();
            try{
                psaset.add(ColorSupported.NOT_SUPPORTED);
                fail("add() doesn't throw Exception when" +
                    "trying to add attribute to unmodifiable attribute set ");
            } catch (UnmodifiableSetException e){
View Full Code Here

     * equals(Object object) method testing.
     */
    public final void testEquals() {

        aset = new HashAttributeSet();
        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
        if (service != null) {
            PrintServiceAttributeSet psaset = service.getAttributes();
            if (aset.addAll(psaset)){
                assertTrue(aset.equals(psaset));
            }
        } else {
            System.out.println("Warning: default print service wasn't found!\n"
View Full Code Here

    private DocPrintJob assignPrintJob(PrintService printService) {
        return printService.createPrintJob();
    }
   
    private PrintService assignPrintService() throws PrintException {
        PrintService printService;
       
        if ((config.getHostname().equalsIgnoreCase("localhost"))
            && (config.getPrintername().equalsIgnoreCase("default"))) {
            printService = PrintServiceLookup.lookupDefaultPrintService();           
        } else {
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.