Print Graphic as Two-Page Report
In this example, the printer is in Graphic mode and prints a graphic as a two-page report. This program performs the following steps:
...
1. Opens the connection to the printer.
2. Prints the first page with a drawn, sample text.
3. Prints the second page with another drawn, sample text.
4. Closes the connection to the printer.
package test;
import com.sap.ip.me.api.pios.connection.*;
import com.sap.ip.me.api.pios.printer.*;
public class TwoPageReport {
public static void main(String[] args) {
int x=15, y=17;
GraphicPrinter gP = null;
try{
Connector conn = Connector.getInstance();
DriverInfo[] driverInfo = conn.listDrivers(ConnectionType.PRINTER);
PrinterParameters params = new PrinterParameters(driverInfo[0]);
params.setPrinterMode(PrinterParameters.GRAPHIC_MODE);
//----------------------(1)--------------------
gP = (GraphicPrinter) conn.open(params);
String[] sFonts = gP.getFontConfigurationManager().listFontNames();
PrinterFont pF = gP.getFont(sFonts[0]);
//----------------------(2)--------------------
gP.drawText(pF, x, y, "First Page", 0);
gP.doPrint(1);
//----------------------(3)--------------------
gP.drawText(pF, x, y, "Second Page", 0);
gP.doPrint(1);
}
catch (Throwable error){
error.printStackTrace();
} finally {
//----------------------(4)--------------------
try {
gP.close();
} catch (Exception ex) {}
}
return;
}
}