JDK-6730467 : PrinterService for network printer via UNC name
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-07-28
  • Updated: 2016-05-25
  • Resolved: 2016-05-25
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
It should be possible to obtain a PrinterService for printing to a network printer via its UNC name, for example \\myserver\myprinter, without having to install the printer locally.

JUSTIFICATION :
We have a web server based application from  which users can print to their local printers by specifying the unc name of the printer. It is not acceptable to have to install some hundreds of local printers on the server.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
PrintServiceLookup.lookupPrintServices() should search for a network printer when called with a PrinterName attribute that contains a network printer name.
ACTUAL -
PrintServiceLookup.lookupPrintServices() returns only printers that are installed locally

---------- BEGIN SOURCE ----------
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashPrintServiceAttributeSet;
import javax.print.attribute.standard.PrinterName;

public class Printer
{	/**
	 * Call with network printer name like \\myserver\myprinter as first argument
	 */
	public static void main( String args[] )
	{
		AttributeSet searchAttributes = new HashPrintServiceAttributeSet();
		searchAttributes.add( new PrinterName( args[0], null ));

		PrintService services[] =
			PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PAGEABLE, searchAttributes );

		if(( services != null ) && ( services.length > 0 ))
		{
			System.out.println( "Found PrintService: " + services[0] );
		}
	}
}

---------- END SOURCE ----------