diff --git a/pretixprint/app/src/main/java/eu/pretix/pretixprint/byteprotocols/ESCLabel.kt b/pretixprint/app/src/main/java/eu/pretix/pretixprint/byteprotocols/ESCLabel.kt index 53a60cf0..29853ec4 100644 --- a/pretixprint/app/src/main/java/eu/pretix/pretixprint/byteprotocols/ESCLabel.kt +++ b/pretixprint/app/src/main/java/eu/pretix/pretixprint/byteprotocols/ESCLabel.kt @@ -11,6 +11,7 @@ import java8.util.concurrent.CompletableFuture import java.io.ByteArrayOutputStream import java.io.InputStream import java.io.OutputStream +import java.util.UUID import java.util.concurrent.TimeUnit @@ -48,25 +49,31 @@ class ESCLabel : StreamByteProtocol { // // Command notes: // ~DY: Store file to printer memory - // Contrary to the documentation, the file name should also contain the extension - - // Delete all files volatile memory - ostream.write("^XA^IDR:*.*^FS^XZ".toByteArray()) + // Contrary to the documentation, the file name should also contain the extension. + // Diverging from the sample in the documentation, we are also naming each file + // explicitly, so that we can delete it rather than issue a "delete everything" command + // ~ID: Delete file or files from printer memory + // As confirmed by Ivar, the delete operations take for bloody ever and slow down the + // printer a lot. As such, we diverge from the official documentation/sample and only + // delete the printed file at the end of the job. Should too many prints fail and clog + // up the volatile memory, the user will have manually clear the memory from the + // printer's menu. // Register image in printer in volatile memory as a PNG val stream = ByteArrayOutputStream() img.compress(Bitmap.CompressFormat.PNG, 100, stream) - ostream.write("~DYR:IMAGE.PNG,B,P,${stream.size()},0,".toByteArray()) + val filename = UUID.randomUUID().toString().replace("-", "").take(8).uppercase() + ostream.write("~DYR:${filename}.PNG,B,P,${stream.size()},0,".toByteArray()) stream.writeTo(ostream) img.recycle() // Create label and print previously transferred image ostream.write("^XA".toByteArray()) - ostream.write("^ILR:IMAGE.PNG^FS".toByteArray()) + ostream.write("^ILR:${filename}.PNG^FS".toByteArray()) ostream.write("^XZ".toByteArray()) // Delete the image from the printer again - ostream.write("^XA^IDR:*.*^FS^XZ".toByteArray()) + ostream.write("^XA^IDR:${filename}.PNG^FS^XZ".toByteArray()) ostream.flush() return ostream.toByteArray()