import com.mobileapps.pcre.*;
class SimpleAppChangePrinter 
{
	public static void main(String [] args) 
	{
		System.getProperties().list(System.out);     
		PCREApplicationClient client = null;
		try 
		{
			client = new PCREApplicationClient("SHASTA_BLUE");
			client.Connect();
			PCREEngine engine = client.OpenEngine();
			PCREJob job = engine.OpenJob("H:\\_test\\SimpleApp_ChangePrinter\\Box.rpt");

			//This line of code will return all the printers available on the report server machine.
			String[] printerNames = client.GetPrinterNames();
			
			//This line of code will print to the screen the names of the available printers
			System.out.println("The available printers are:");
			for(int i=0; i<printerNames.length; i++)
				System.out.println("	"+printerNames[i]);

			//This code will print to the first specified printer which is a remote printer
			//which is configured to print to the default letter size with the tray auto selected
			System.out.println("Now printing to the first specified printer:");
			job.SelectPrinterByName("\\\\WOPOR\\HP LaserJet 4 Plus - Dev", null);
			job.OutputToPrinter(1);
			job.Start();

			//This code will print to the second specified printer which is a local printer
			//which is configured to print to the default letter size with the tray auto selected
			System.out.println("Now printing to the second specified printer:");
			job.SelectPrinterByName("Local HP LaserJet 4000 Series PS", null);
			job.OutputToPrinter(1);
			job.Start();

			//This code will print to the third specified printer which is a remote printer
			//which is configured to print to legal sized paper through tray 1 (manual feed)
			System.out.println("Now printing to the third specified printer:");
			job.SelectPrinterByName("\\\\WOPOR\\HP LaserJet 4000 LMF", null);
			job.OutputToPrinter(1);
			job.Start();

			//This code will print to the fourth specified printer which is a local printer
			//which is configured to print to legal sized paper through tray 1 (manual feed)
			System.out.println("Now printing to the fourth specified printer:");
			job.SelectPrinterByName("Local 2 HP LaserJet 4000 Series PS", null);
			job.OutputToPrinter(1);
			job.Start();
			job.Close();
			System.out.println("Report Finished");
			engine.Close();
		}
		catch ( PCREError ex )
		{
			System.out.println("Exception: "+ex);
		}
		catch (GatewayShuttingDown error) 
		{
			System.out.println("GatewayShuttingDown: " + error);
		}
		finally
		{
			if (client !=null) client.Quit();
		}        
	}
}
