question

ihor avatar image
ihor asked ihor commented

Receipt quality

Hi,

I printing receipts using ViewPrintJob. Everything is working fine, but the quality of printed receipt is very bad. It has some kind of distortion.

My source view is 384dp width and dynamic height depends on height of receipt. I've put breakpoints to "writeBitmapChucks" method in SDK and the result bitmap is distorted(I've made visual check of bitmap through debug tools in Android Studio) . Bitmap that created has Bitmap.Config.RGB_565 colorspace and compressed 100 quality(values taken from method sources), so it should looks fine.

image description

Possible I should use some flags or made some another set up of my source view to improve quality. Is it any way to improve quality? What is the best practice?

Looking forward to hearing from someone.

4 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

It'd be useful if you can link to a copy of source bitmap (what you are passing into the print job ... you'll need to encode it as a PNG), and a picture of what the receipt looks like.

0 Likes 0 ·
ihor avatar image ihor commented ·

I didn't pass an image to ViewPrintJob. I pass to print job ScrollView that contains TextViews, Images etc. writeBitmapChucks - it's a method from ViewPrintJob sources. ViewPrintJob makes a "screenshot" by itself.

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

... "It'd be useful if you can link to a copy of ... and a picture of what the receipt looks like."

0 Likes 0 ·
ihor avatar image ihor commented ·

Example image has been attached.

0 Likes 0 ·

1 Answer

Jeffrey Blattman avatar image
Jeffrey Blattman answered ihor commented

The font you use matters a lot. This printer is low res and monochrome. You don't get the visual blending of edges and colors you do on a screen. Here's how we set up the font,

 public class FontManager {

  public final Typeface RECEIPT_FONT;
  public final Typeface RECEIPT_FONT_BOLD;

  private final Context mContext;

  public FontManager(Context context, int receiptWidth) {
    mContext = context;
    if (receiptWidth > 384) {
      RECEIPT_FONT = Typeface.defaultFromStyle(0);
      RECEIPT_FONT_BOLD = Typeface.defaultFromStyle(Typeface.BOLD);
    } else {
      RECEIPT_FONT = Typeface.createFromAsset(context.getAssets(), "RobotoCondensed-Regular.ttf");
      RECEIPT_FONT_BOLD = Typeface.createFromAsset(context.getAssets(), "RobotoCondensed-Bold.ttf");
    }
  }
}

And for example,

  private TextView createTextView(Typeface typeface, int typefaceType, float fontSize, int gravity, CharSequence text) {
    TextView tv = new TextView(mContext);
    tv.setText(text);
    tv.setGravity(gravity);
    tv.setTypeface(typeface, typefaceType);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
    tv.setIncludeFontPadding(false);
    tv.getPaint().setAntiAlias(false);
    tv.setTextColor(Color.BLACK);

    return tv;
  }

Where the first arg is one of the Typefaces from FontManager.

This is just an example and isn't part of our SDK. You'll probably need to experiment on your own to find a font that works for you.

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ihor avatar image ihor commented ·

Thank you a lot, Jeff. I will try your recommendations.

0 Likes 0 ·

Welcome to the
Clover Developer Community