Printing a document
You use methods from the ODServer and ODFolder classes to help you find a printer and print a document to that server.
About this task
The following example uses ODServer and ODFolder methods to list the printers that are available on the server and to print a document to the specified server printer. This example also uses ODServer methods to prepare for logon, open the specified folder, and log off.
- initialize
- logon
- openFolder
- getServerPrinters
- logoff
- terminate
- search
- printDocuments
- close
- Server name
- Port
- User Id
- Password
- Folder name
- Printer name
import java.util.*;
import java.io.*;
import com.ibm.edms.od.*;
public class TcPrintHit
{
public static void main ( String argv[] )
{
ODServer odServer;
ODFolder odFolder;
ODHit odHit;
Vector hits;
Vector hit_to_print;
String [] printers;
String printer_name;
boolean match;
int j;
//----------
// If too few parameters, display syntax and get out
//----------
if ( argv.length < 6 )
{
System.out.println( "usage: java TcPrintHit <server> <port> <userid> <password> <folder> <printer>" );
return;
}
try
{
//----------
// Set the stage
//----------
System.out.println( "Testcase TcPrintHit started." );
System.out.println( "This testcase should:" );
System.out.println( " Logon to the specified server" );
System.out.println( " Display the list of printers available on the server" );
System.out.println( " Open the specified folder" );
System.out.println( " Search the folder using the default criteria" );
System.out.println( " Display the number of hits" );
System.out.println( " Print the first hit to the specified server printer" );
System.out.println( "" );
System.out.println( "---------------------------------------------------" );
System.out.println( "" );
//----------
// Logon to specified server
//----------
ODConfig odConfig = new ODConfig();
if(odConfig != null)
{
odServer = new ODServer(odConfig );
odServer.initialize( "TcPrintHit.java" );
odServer.setPort(Integer.parseInt(argv[1]));
System.out.println( "Logging on to " + argv[0] + " server with user " + argv[2] + "..." );
odServer.logon( argv[0], argv[2], argv[3]);
//----------
// If any server printers are available on the server
//----------
System.out.println( "Retrieving list of server printers..." );
printer_name = argv[5];
printers = odServer.getServerPrinters( );
if ( printers.length > 0 )
{
//----------
// List the available server printers
//----------
System.out.println( "There are " + printers.length + " printers available on the server:" );
match = false;
for( j = 0; j < printers.length; j++ )
{
System.out.println( " " + printers[j] );
if ( printers[j].equals( printer_name ) )
match = true;
}
if ( match )
{
//----------
// Open the specified folder and search with the default criteria
//----------
System.out.println( "Opening " + argv[4] + " folder..." );
odFolder = odServer.openFolder( argv[4] );
System.out.println( "Searching with default criteria..." );
hits = odFolder.search( );
System.out.println( " Number of hits: " + hits.size( ) );
//----------
// Print the first hit to the specified server printer
//----------
if ( hits.size( ) > 0 )
{
hit_to_print = new Vector( );
odHit = (ODHit)hits.elementAt( 0 );
hit_to_print.addElement( odHit );
System.out.println( "Printing first hit to " + printer_name + "..." );
odFolder.printDocuments( hit_to_print, printer_name,2);
}
else
System.out.println( "There is no document to print" );
odFolder.close( );
}
else
System.out.println( "The specified printer (" + printer_name +
") is not available on this server" );
}
else
System.out.println( "No printers are avilable on this server" );
//----------
// Cleanup
//----------
odServer.logoff( );
odServer.terminate( );
System.out.println( "" );
System.out.println( "---------------------------------------------------" );
System.out.println( "" );
System.out.println( "Testcase TcPrintHit completed - Analyze the results" );
System.out.println( "" );
}
}
catch ( ODException e )
{
System.out.println( "ODException: " + e );
System.out.println( " id = " + e.getErrorId( ) );
System.out.println( " msg = " + e.getErrorMsg( ) );
e.printStackTrace( );
}
catch ( Exception e2 )
{
System.out.println( "exception: " + e2 );
e2.printStackTrace( );
}
}
}
When you click the Print icon in the web browser toolbar while viewing a line data report from a folder delivered by ODWEK, you are prompted to select a printer. Some users are unsure how to print a specific range of pages, versus printing all pages.
To be able to print a range of pages, click OK on the first print window, where the printer name and properties are specified. After you click OK, a second print window displays, where you can specify margins and the range of pages to print. This print page-range behavior is under control of a Java™ API that is started by ODWEK.