Android如何通过蓝牙打印机打印文本对齐和表格样式?
我正试图通过蓝牙打印机打印一些信息。我可以打印纯文本。但我不能添加任何对齐方式和文本格式。我还想打印一些数据,比如tableview 文本格式和对齐方式应如下:-Android如何通过蓝牙打印机打印文本对齐和表格样式?,android,text-alignment,plaintext,richtext,Android,Text Alignment,Plaintext,Richtext,我正试图通过蓝牙打印机打印一些信息。我可以打印纯文本。但我不能添加任何对齐方式和文本格式。我还想打印一些数据,比如tableview 文本格式和对齐方式应如下:- String titleStr = "Title" + "\n\n"; StringBuilder contentSb = new StringBuilder(); contentSb.append("Item1 : 1221" + "\n"); contentSb.append("Item2
String titleStr = "Title" + "\n\n";
StringBuilder contentSb = new StringBuilder();
contentSb.append("Item1 : 1221" + "\n");
contentSb.append("Item2 : test" + "\n");
StringBuilder content2Sb = new StringBuilder();
content2Sb.append("BANK : Us. 1.600" + "\n");
String message = "This is for test." + "\n\n";
long milis = System.currentTimeMillis();
String date = DateUtil.timeMilisToString(milis, "dd-MM-yy / HH:mm") + "\n\n\n\n";
byte[] titleByte = titleStr.getBytes();
byte[] content1Byte = contentSb.toString().getBytes();
byte[] messageByte = message.getBytes();
byte[] content2Byte = content2Sb.toString().getBytes();
byte[] dateByte = date.getBytes();
byte[] totalByte = new byte[titleByte.length + content1Byte.length + messageByte.length +
content2Byte.length + dateByte.length];
int offset = 0;
System.arraycopy(titleByte, 0, totalByte, offset, titleByte.length);
offset += titleByte.length;
System.arraycopy(content1Byte, 0, totalByte, offset, content1Byte.length);
offset += content1Byte.length;
System.arraycopy(messageByte, 0, totalByte, offset, messageByte.length);
offset += messageByte.length;
System.arraycopy(content2Byte, 0, totalByte, offset, content2Byte.length);
offset += content2Byte.length;
System.arraycopy(dateByte, 0, totalByte, offset, dateByte.length);
mmOutputStream.write(totalByte);
表格格式的数据应如下:-
String titleStr = "Title" + "\n\n";
StringBuilder contentSb = new StringBuilder();
contentSb.append("Item1 : 1221" + "\n");
contentSb.append("Item2 : test" + "\n");
StringBuilder content2Sb = new StringBuilder();
content2Sb.append("BANK : Us. 1.600" + "\n");
String message = "This is for test." + "\n\n";
long milis = System.currentTimeMillis();
String date = DateUtil.timeMilisToString(milis, "dd-MM-yy / HH:mm") + "\n\n\n\n";
byte[] titleByte = titleStr.getBytes();
byte[] content1Byte = contentSb.toString().getBytes();
byte[] messageByte = message.getBytes();
byte[] content2Byte = content2Sb.toString().getBytes();
byte[] dateByte = date.getBytes();
byte[] totalByte = new byte[titleByte.length + content1Byte.length + messageByte.length +
content2Byte.length + dateByte.length];
int offset = 0;
System.arraycopy(titleByte, 0, totalByte, offset, titleByte.length);
offset += titleByte.length;
System.arraycopy(content1Byte, 0, totalByte, offset, content1Byte.length);
offset += content1Byte.length;
System.arraycopy(messageByte, 0, totalByte, offset, messageByte.length);
offset += messageByte.length;
System.arraycopy(content2Byte, 0, totalByte, offset, content2Byte.length);
offset += content2Byte.length;
System.arraycopy(dateByte, 0, totalByte, offset, dateByte.length);
mmOutputStream.write(totalByte);
我需要一些帮助
这里我包括我尝试的代码:-
String titleStr = "Title" + "\n\n";
StringBuilder contentSb = new StringBuilder();
contentSb.append("Item1 : 1221" + "\n");
contentSb.append("Item2 : test" + "\n");
StringBuilder content2Sb = new StringBuilder();
content2Sb.append("BANK : Us. 1.600" + "\n");
String message = "This is for test." + "\n\n";
long milis = System.currentTimeMillis();
String date = DateUtil.timeMilisToString(milis, "dd-MM-yy / HH:mm") + "\n\n\n\n";
byte[] titleByte = titleStr.getBytes();
byte[] content1Byte = contentSb.toString().getBytes();
byte[] messageByte = message.getBytes();
byte[] content2Byte = content2Sb.toString().getBytes();
byte[] dateByte = date.getBytes();
byte[] totalByte = new byte[titleByte.length + content1Byte.length + messageByte.length +
content2Byte.length + dateByte.length];
int offset = 0;
System.arraycopy(titleByte, 0, totalByte, offset, titleByte.length);
offset += titleByte.length;
System.arraycopy(content1Byte, 0, totalByte, offset, content1Byte.length);
offset += content1Byte.length;
System.arraycopy(messageByte, 0, totalByte, offset, messageByte.length);
offset += messageByte.length;
System.arraycopy(content2Byte, 0, totalByte, offset, content2Byte.length);
offset += content2Byte.length;
System.arraycopy(dateByte, 0, totalByte, offset, dateByte.length);
mmOutputStream.write(totalByte);
这与iText有什么关系?你谈论的是纯文本,而不是PDF。您的问题不包含任何代码。这是一个非常奇怪的问题。实际上我需要一个解决方案。我可以打印纯文本。但我不能格式化。如果有可能做到这一点,通过pdf,然后我会使用它。这就是我贴标签的原因itext@BrunoLowagie我包括了我的示例代码。是否可以先创建pdf,然后通过蓝牙以类似我的图像的格式打印?我知道如何使用iText创建pdf,我已经编写了数千个关于如何使用iText的示例,但这不是你的问题。