I want to print a ScrollView using Datecs Termal printer. The view is a ticket like as a purchase ticket. I want to measure exactly 300 mm height in the paper. I using this method to convert Scrollview to Bitmap:
public static Bitmap getBitmapFromView(View view, int height, int width) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = view.getBackground();
canvas.drawColor(Color.WHITE);
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return bitmap;
}
The problem is when hidden or show textviews, change height of Bitmap. In addition it also changes size depending on the density of the screen. I want to fill the 300 mm of paper with the view and blank spaces.
I have try two solutions:
-Feed paper as many lines as there is difference between the height of the view and 300mm
-Generate bitmap to heigh is exactly 300mm.
I could not do it in any way.
Datecs sdk contain this method to feed paper:
public void feedPaper(int lines) throws IOException {
if (lines >= 0 && lines <= 255) {
byte[] buf = new byte[]{27, 74, (byte)lines};
synchronized(this) {
this.write(buf);
}
} else {
throw new IllegalArgumentException("The lines is out of range");
}
}
But I do not know the relation between the height of the bitmap, the height of each line and the 300 mm of the paper.
Can anybody help me? Thank you very much!