Print Image in Line Mode
In this example, the printer is in Line mode and prints a bitmap image (using test.bmp in the c:\Temp\ directory). The program performs the following steps:
...
1. Lists the drivers.
2. Opens the image file.
3. Opens the connection to the printer.
4. Loads the image into the printer.
5. Prints the image.
6. Closes the connection to the printer.
package test;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import com.sap.ip.me.api.pios.connection.*;
import com.sap.ip.me.api.pios.printer.*;
public class ImageLineMode {
public static void main(String[] args) {
LinePrinter lP = null;
PrinterImage image = null;
try {
Connector conn = Connector.getInstance();
//----------------------(1)--------------------
DriverInfo[] driverInfo = conn.listDrivers(ConnectionType.PRINTER);
PrinterParameters params = new PrinterParameters(driverInfo[0]);
params.setPrinterMode(PrinterParameters.LINE_MODE);
try {
//-------------------(2)--------------------
File testImage = new File("C:\\TEMP\\test.bmp");
if (testImage.exists()) {
BufferedInputStream bfis = null;
try {
bfis = new BufferedInputStream(new FileInputStream(testImage));
int bufferSize = (int)testImage.length();
byte[] imageBytes = new byte[bufferSize];
int i = bfis.read(imageBytes, 0, bufferSize);
//-------------(3)--------------------
lP = (LinePrinter) conn.open(params);
if (i > 0) {
image = lP.createImage("test", PrinterImage.IMAGE_BMP, imageBytes);
//----------(4)--------------------
lP.loadImage(image);
}
}
finally {
if (bfis != null) bfis.close();
}
}
}
catch (Throwable tFile) {
tFile.printStackTrace();
}
String[] sFonts = lP.getFontConfigurationManager().listFontNames();
PrinterFont pF = lP.getFont(sFonts[0]);
lP.printText(pF, "", LinePrinter.NO_ALIGNMENT);
//----------------------(5)--------------------
lP.printImage(image.getName(), LinePrinter.ALIGN_CENTER);
lP.doPrint(1);
}
catch (Throwable error){
error.printStackTrace();
} finally {
//----------------------(6)--------------------
try {
lP.close();
} catch (Exception ex) {}
}
return;
}
}