Come utilizzare sendToPrinter con il protocollo SharedPrinter

Problema

Il componente sendToPrinter supporta i seguenti protocolli:

  • CUPS
  • DirectIP
  • LPD
  • SharedPrinter
  • CIFS

Nel caso di SharedPrinter, l'URI del server non viene utilizzato, e viene utilizzato solo il nome della stampante. Il valore per il nome della stampante può essere tuttavia difficile da trovare, in quanto può differire dall'UNC. 

Soluzione

Il seguente codice può essere utilizzato in un'operazione executeScript per elencare le stampanti condivise disponibili sul server:

import javax.print.*;

PrintServiceLookup.lookupPrintServices(null, null);

Avviate-----");

for(PrintService svc:svcs){

if(svc!=null){

"+svc.getName());

}

}

System.out.println("PrintServices Log

Fine-----");

 

Il risultato è il seguente output nel file di log del server:

[06/05/16

13:17:15:746 BST] 0000026d SystemOut O PrintServices Log Start-----

[06/05/16
13:17:15:762 BST] 0000026d SystemOut O PrintSvc : ZDesigner S4M-300dpi ZPL

[06/05/16
13:17:15:762 BST] 0000026d SystemOut O PrintSvc : server

[06/05/16
13:17:15:762 BST] 0000026d SystemOut O PrintSvc : Send To OneNote 2013

[06/05/16
13:17:15:762 BST] 0000026d SystemOut O PrintSvc : Microsoft XPS Document Writer

[06/05/16
13:17:15:763 BST] 0000026d SystemOut O PrintSvc : LPT1

[06/05/16
13:17:15:763 BST] 0000026d SystemOut O PrintSvc : Fax

[06/05/16
13:17:15:763 BST] 0000026d SystemOut O PrintSvc : Epson ESC/P-R

[06/05/16
13:17:15:763 BST] 0000026d SystemOut O PrintSvc : Adobe PDF

[06/05/16

13:17:15:763 BST] 0000026d SystemOut O PrintSvc : \\EDINBURGH-PRINT\Canon EDI-COE

[06/05/16

13:17:15:763 BST] 0000026d SystemOut O PrintServices Log End-----

È possibile utilizzare questo output per configurare l'operazione sendToPrinter:

KB-Capture