我在同时打印账单的图像(可绘制)和文本(23行)时遇到问题。如果我省略图像部分,则所有文本都可以正常打印,但是如果我将打印图像放在文本之前(作为标题的徽标),则仅打印4行,然后停止打印。
OutputStream outputStream = mBluetoothSocket
.getOutputStream();
os = outputStream;
String separador = "--------------------------------";
byte[] onlybold = new byte[]{0x1B, 0x21, 0x08}; // 1- only bold text
byte[] normaltext = new byte[]{0x1B, 0x21, 0x00}; // 0- normal size text
byte[] boldmedium = new byte[]{0x1B, 0x21, 0x20}; // 2- bold with medium text
printPhoto(R.drawable.logogray); // if i omit this line the flow of the printing code reaches the end
String preInstitucion = institucion.trim();
String strInstitucion = "";
if (preInstitucion.length() > 32) {
String oneInstitucion = preInstitucion.substring(0, 31);
int lastSpace = oneInstitucion.lastIndexOf(" ");
strInstitucion = oneInstitucion.substring(0, lastSpace - 1) + "\n" + preInstitucion.substring(lastSpace + 1, lastSpace + 30);
} else {
strInstitucion = preInstitucion;
}
String HEADER = "";
os.write(onlybold);
HEADER = "\n\n" + strInstitucion.trim() + "\n" +
direccion1.trim() + "\n" +
direccion2.trim() + "\n" +
telefono.trim() + "\n";
os.write(HEADER.getBytes()); // << otherwise, when I am sending the image to print, this is the last line that is executed and omits everything else RELATED TO PRINTING
os.write(normaltext);
String BILL = separador + "\n" ;
BILL = BILL + String.format("%1$10s %2$13s", "Codigo", contrib.getString(0).trim());
BILL = BILL + "\n";
BILL = BILL + String.format("%1$10s %2$13s", "Medidor", medidor.getString(0).trim());
BILL = BILL + "\n";
BILL = BILL + separador;
BILL = BILL + "\n";
BILL = BILL + "Nombre del Contribuyente:";
os.write(BILL.getBytes());
os.write(onlybold);
BILL = "";
BILL = BILL + "\n" + contrib.getString(1).toUpperCase().trim();
os.write(BILL.getBytes());
os.write(normaltext);
BILL = "";
BILL = BILL + "\n" + "Direccion del servicio:";
os.write(BILL.getBytes());
os.write(onlybold);
BILL = "";
BILL = BILL + "\n" + contrib.getString(2).trim();
os.write(BILL.getBytes());
os.write(normaltext);
BILL = "";
BILL = BILL
+ "\n" + separador;
BILL = BILL + "\n" + String.format("%1$-14s %2$14s", "Lect. Anterior", String.valueOf(ultimalectura));
BILL = BILL + "\n" + String.format("%1$-14s %2$14s", "Lect. Actual", String.valueOf(inputlectura));
BILL = BILL + "\n" + String.format("%1$-14s %2$14s", "Consumo metros", String.valueOf(metros));
BILL = BILL + "\n" + String.format("%1$-14s %2$14s", "Mes de Lectura", cmonth.trim() + "/" + String.valueOf(year).substring(2));
这是我第一次使用打印功能进行开发。 希望您能帮助我,我真的很困惑!