-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Woking Fine But some time image not printing printing bad character in android #42
Comments
Hi @lavahasif However, in my point of view, first we need to isolate the problem. if not: RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();
Bitonal algorithm = new BitonalOrderedDither();
EscPosImage escposImage = new EscPosImage(new CoffeeImageAndroidImpl(bitmap), algorithm);
escpos.write(imageWrapper, escposImage);
// save imageWrapper to one file to print...
byte[] bytes = imageWrapper.getBytes(escposImage);
// create one file and save it...
// save the bitmap to another file (png)
them, when the problem happen, count on me, |
Thank you for your quick replay. ### {I'm misconfused about "can you suggest to preview escposImage as image file" yes I want to save the esposimage variable as a image file for checking(I have one UI viewer of escpos-image dump) .some time the pritnting not work properly (https://user-images.githubusercontent.com/22430922/90307980-2bb92b80-def9-11ea-8823-2a6388d3a844.jpeg ) not always . so i want to check where it happen. |
I made one variant of EscPos Class, you can use it to dump file content on android You can use traditional write that only dump the escpos_image, I hope this help you. package com.github.anastaciocintra.escposcoffeesamples.androidimage;
import android.content.Context;
import android.graphics.Bitmap;
import com.github.anastaciocintra.escpos.EscPos;
import com.github.anastaciocintra.escpos.image.Bitonal;
import com.github.anastaciocintra.escpos.image.EscPosImage;
import com.github.anastaciocintra.escpos.image.ImageWrapperInterface;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class EscposWithDumpAndroid extends EscPos {
private Context context;
/**
* creates an instance based on outputStream.
*
* @param outputStream can be one file, System.out or printer...
* @see OutputStream
*/
public EscposWithDumpAndroid(OutputStream outputStream, Context context) {
super(outputStream);
this.context = context;
}
@Override
public EscPos write(ImageWrapperInterface wrapper, EscPosImage image) throws IOException {
// call original write
super.write(wrapper, image);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String strDate = dateFormat.format(new Date());
String fileName = strDate + ".dump";
// creating file...
// https://developer.android.com/training/data-storage/app-specific
FileOutputStream fileDump = context.openFileOutput(fileName, Context.MODE_PRIVATE);
// dump escpos_image
byte[] bytes = wrapper.getBytes(image);
fileDump.write(bytes);
// close file
fileDump.close();
return this;
}
// other and more complete option
// dump both files, the EscposImage and the bitmap
public EscPos writeAndDumpFiles(ImageWrapperInterface wrapper, Bitonal algorithm, Bitmap bitmap) throws IOException {
EscPosImage escposImage = new EscPosImage(new CoffeeImageAndroidImpl(bitmap), algorithm);
super.write(wrapper, escposImage);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String strDate = dateFormat.format(new Date());
String fileName = strDate + ".dump";
// creating file...
// https://developer.android.com/training/data-storage/app-specific
FileOutputStream fileDump = context.openFileOutput(fileName, Context.MODE_PRIVATE);
// dump escpos_image
byte[] bytes = wrapper.getBytes(escposImage);
fileDump.write(bytes);
// close file
fileDump.close();
// Bitmap
fileName = strDate + ".png";
fileDump = context.openFileOutput(fileName, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileDump);
fileDump.close();
return this;
}
} |
Hi @lavahasif You can log the image dimensions to diagnose if is this happening. |
Thank you for your effort.Some time i feel it.i already mention above .For checking i print 20 page simultaneously .i did'nt get any garbage .some time get above character.my customer have daily 300 bills.some time they get garbage print.so i change the above model now i am using printer font with logo now no problem.some time i feel may be my app have memory leak(if i get garbage then i try to restart the printer then take bill get correctly). Due to that reason some time getting that print.Thanks |
My printing Method was :- Collect Printing Data --->Convert to html (width 300px 'variation get big or overflow print(i didnt get any garbage )'-->html to image(Here i try to save 60 or above continous save bill to internal storage no problem )-->escpos |
hi, i have the same problem, in my case it only works for the first time after i turn on the printer, and then only print random charatcters. My solution is this: after i create escpos object then i call escPos.initializePrinter(); and after a the full printing proces i call it once again before close: escPos.flush();escPos.initializePrinter();escPos.close(); And it wokrs for me, but its not perfect because the justification is not ok... And of course it depends on the printer eg on the sam4s printer works fine without any tricks, and a on chinise noname printer i need this tricks above |
print 20 print continuos no problem but some time
some time showing this
anyway thank you for solution helped
code:
public void run(String ip, Bitmap bmp, PrintBillFormat printBillFormat) {
String host = ip;
int port = 9100;
try (TcpIpOutputStream stream = new TcpIpOutputStream(host, port)) {
EscPos escpos = new EscPos(stream);
can you suggest to preview escposImage as image file
The text was updated successfully, but these errors were encountered: