2 Replies Latest reply: Mar 26, 2009 11:25 AM by 843807 RSS

    Accessing printer port,different from LPT1

    843807
      PrinterJob printerJob = PrinterJob.getPrinterJob();
      
      PageFormat pageFormat = printerJob.defaultPage();
      pageFormat.setOrientation(PageFormat.LANDSCAPE);
      
      printerJob.setPrintable(this, pageFormat);
      printerJob.setJobName("job name");
      
      if (printerJob.printDialog()) {
          printerJob.print();
      }
      Is it possible to choose a printer port (different from LPT1) ?

      Thanks
        • 1. Re: Accessing printer port,different from LPT1
          Alan.M
          Hi.
          You may be able to set it via the PrintRequestAttributeSet when you invoke the print dialog window, you sen the attribute

          if (printerJob.printDialog(attribute))



          Hope this could help

          Regards,
          Alan Mehio
          London, UK
          • 2. Re: Accessing printer port,different from LPT1
            843807
            Thanks for your answer. Here's my code :
            // Step 1: Set up initial print settings.
            PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
            // Step 2: Obtain a print job.
            PrinterJob pj = PrinterJob.getPrinterJob();
            // Step 3: Find print services.
            PrintService[] services = PrinterJob.lookupPrintServices();
            if (services.length > 0) {
                 pj.setPrintService(services[0]); 
                 if (pj.printDialog(aset)) {
                         // Step 4: actualservice contains the selected printservice
                      Win32PrintService actualservice = (Win32PrintService) pj.getPrintService();
                 }
            }
            I need to do something like 'actualservice.getPort()'. I don't know if it's possible..