Print Centered Text in Line Mode
In this example, the printer is in Line mode and a line is printed in the center of the page. The program performs the following steps:
...
1. Opens the connection to the printer.
2. Prints the text with center alignment.
3. 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 TextCenterLineMode {
public static void main(String[] args) {
LinePrinter lP = null;
try{
Connector conn = Connector.getInstance();
DriverInfo[] driverInfo = conn.listDrivers(ConnectionType.PRINTER);
PrinterParameters params = new PrinterParameters(driverInfo[0]);
params.setPrinterMode(PrinterParameters.LINE_MODE);
//----------------------(1)--------------------
lP = (LinePrinter) conn.open(params);
String[] sFonts = lP.getFontConfigurationManager().listFontNames();
PrinterFont pF = lP.getFont(sFonts[0]);
lP.printText(pF, "", LinePrinter.NO_ALIGNMENT);
//----------------------(2)--------------------
lP.printText(pF, "Center of the line.", LinePrinter.ALIGN_CENTER);
lP.doPrint(1);
}
catch (Throwable error){
error.printStackTrace();
} finally {
//----------------------(3)--------------------
try {
lP.close();
} catch (Exception ex) {}
}
return;
}
}