I can print a receipt (byte[] printer format) via a thermal printer, like this :
// Print a receipt
OutputStream outputStream = mPrinterSocket.getOutputStream();
for (byte[] packet : content)
outputStream.write(packet);
outputStream.flush();
But I can not manage to save a receipt (byte[] printer format) into a file (pdf or image). I tried :
// Save a receipt
try (OutputStream outputStream = new FileOutputStream(filePath)) {
for (byte[] packet : content) {
outputStream.write(packet);
outputStream.flush();
}
} catch (Exception exception) {
exception.printStackTrace();
}
But it returned a corrupted file, containing:
䀛琛ᬐšℝ䴑ਊℝ䴀੍੍ㄊ⼵㔰ㄯ‹ㄱ㈺‱†††††慔汢䔛ਁ′潂獩潳獮†††††††††††ᬊE‱潃慣†††††††††††⸲〲ᬊE‱慆瑮††††††††††⸲〲ⴊⴭⴭⴭⴭⴭⴭⴭⴭⴭⴭⴭⴭⴭⴭⴭਭ䔛吁呏䱁†††††††††䔠剕㐠㐮ਰਊ䔛䴀牥楣⃠楢湥⁴ਡਊਊᴊV
Is the process to "print a byte[] to file" different from "save a byte[] to file"? For example, I use the character {0x1b, 0x45, 0x01} to put a text in bold, is this a problem? I would like to avoid reformatting everything or using an external library.