123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package com.printer.demo.utils;
- import android.util.Log;
- import com.printer.sdk.PrinterConstants.LableFontSize;
- import com.printer.sdk.PrinterConstants.LablePaperType;
- import com.printer.sdk.PrinterConstants.PAlign;
- import com.printer.sdk.PrinterConstants.PBarcodeType;
- import com.printer.sdk.PrinterConstants.PRotate;
- import com.printer.sdk.PrinterInstance;
- public class PrintLabel80_1 {
-
- private static int MULTIPLE = 2;
- private static final int line_width_border = 2;
- private static final int page_width = 260 * MULTIPLE;
- private static final int page_height = 165 * MULTIPLE;
- private static final int margin_horizontal = 2 * MULTIPLE;
- private static final int top_left_x = margin_horizontal;
- private static final int margin_vertical = 2 * MULTIPLE;
- private static final int top_left_y = margin_vertical;
- private static final int border_width = page_width - 2 * margin_horizontal;
- private static final int border_height = page_height - 2 * margin_vertical;
- private static final int top_right_x = top_left_x + border_width;
- private static final int bottom_left_y = top_left_y + border_height;
- private static final int bottom_right_y = bottom_left_y;
- private static final int bottom_right_x = top_right_x;
- private static final int row36_column1_width = 10 * MULTIPLE;
- private static final int row37_column3_width = 20 * MULTIPLE;
- private static final int row36_sep1_x = top_left_x + row36_column1_width;
- private static final int row37_sep2_x = top_right_x - row37_column3_width;
- private static final int[] row_height = { 10 * MULTIPLE * 2, 27 * MULTIPLE, 27 * MULTIPLE, 27 * MULTIPLE,
- 27 * MULTIPLE };
- private static final String TAG = "PrintLabel";
- public void doPrint(PrinterInstance iPrinter) {
- iPrinter.pageSetup(LablePaperType.Size_80mm, page_width, page_height);
- drawBox(iPrinter);
-
- drawRowContent(iPrinter);
- iPrinter.print(PRotate.Rotate_0, 1);
- }
- private void drawRowContent(PrinterInstance iPrinter) {
-
-
-
-
-
-
-
- iPrinter.drawText(top_left_x, top_left_y, "全程路运 12-02 04:22浙江", LableFontSize.Size_32, PRotate.Rotate_0, 1, 0,
- 0);
-
-
-
- iPrinter.drawText(top_left_x + 2 * (border_width) / 3 + 20, top_left_y,
- top_left_x + 7 * (border_width) / 9 + 50, top_left_y + row_height[1], PAlign.END, PAlign.END, "邮特",
- LableFontSize.Size_32, 1, 0, 0, 0, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 7 * (border_width) / 9 + 30, top_left_y, top_right_x, top_left_y + row_height[1],
- PAlign.END, PAlign.END, "2014", LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1], top_right_x,
- top_left_y + row_height[1] * 2, PAlign.CENTER, PAlign.END, "特快", LableFontSize.Size_32, 1, 0, 0, 0,
- PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x, top_left_y + row_height[1] * 2, top_left_x + 5 * (border_width) / 9,
- top_left_y + row_height[1] * 3, PAlign.START, PAlign.END, "义乌市 ", LableFontSize.Size_48, 1, 0, 0, 0,
- PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 5 * (border_width) / 9, top_left_y + row_height[1] * 2 + 26,
- top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 3, PAlign.START, PAlign.START, "局收",
- LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 2 + 26,
- top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 3, PAlign.END, PAlign.START, "号码",
- LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 2, top_right_x,
- top_left_y + row_height[1] * 3, PAlign.CENTER, PAlign.END, "58280" + " ", LableFontSize.Size_24, 1, 0,
- 2, 0, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x, top_left_y + row_height[1] * 3, top_left_x + 5 * (border_width) / 9,
- top_left_y + row_height[1] * 4, PAlign.START, PAlign.END, "江西集散 7件", LableFontSize.Size_32, 1, 0, 0, 0,
- PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 5 * (border_width) / 9, top_left_y + row_height[1] * 3 + 26,
- top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 4, PAlign.START, PAlign.START, "局发",
- LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 2 * (border_width) / 3, top_left_y + row_height[1] * 3 + 26,
- top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 4, PAlign.END, PAlign.START, "重量",
- LableFontSize.Size_24, 1, 0, 0, 0, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x + 7 * (border_width) / 9, top_left_y + row_height[1] * 3, top_right_x,
- top_left_y + row_height[1] * 4, PAlign.CENTER, PAlign.END, " " + "10" + " ", LableFontSize.Size_24, 1,
- 0, 2, 0, PRotate.Rotate_0);
-
-
-
-
-
-
- iPrinter.drawBarCode(0, top_left_y + row_height[1] * 4, "33000166322061001131582800603",
- PBarcodeType.CODE128, 1, 60, PRotate.Rotate_0);
-
- iPrinter.drawText(top_left_x, top_left_y + bottom_right_y - 30, bottom_right_x, bottom_right_y, PAlign.START,
- PAlign.START, "33000166-32206100-1-131-5828-0060-3", LableFontSize.Size_24, 1, 0, 0, 0,
- PRotate.Rotate_0);
- }
- private void drawHorizontalSeparator(PrinterInstance iPrinter, int start_x, int end_x) {
- int temp = top_left_y;
- for (int i = 1; i < row_height.length; i++) {
- temp += row_height[i];
- int start_x1 = top_left_x + 7 * (border_width) / 9;
- int end_x1 = top_left_x + 5 * (border_width) / 9;
-
- iPrinter.drawLine(2, start_x, temp, end_x1, temp, true);
-
-
- }
- }
- private void drawVerticalSeparator(PrinterInstance iPrinter) {
- int start_x = top_left_x + row_height[1];
- int start_y = top_left_y + row_height[0] + row_height[1];
- int end_x = start_x;
- int end_y = top_left_y + row_height[0] + row_height[1] * 5;
-
- iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
-
- start_x = top_left_x + (top_right_x - top_left_x) / 2;
- start_y = top_left_y;
- end_x = start_x;
- end_y = start_y + row_height[0];
- Log.i(TAG, "start_x;" + start_x + "end_x:" + end_x);
- iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
-
- start_x = top_left_x + 3 * (top_right_x - top_left_x) / 4;
- start_y = top_left_y + row_height[0] + row_height[1];
- end_x = start_x;
- end_y = bottom_right_y;
- iPrinter.drawLine(line_width_border, start_x, start_y, end_x, end_y, true);
- }
- private void drawBox(PrinterInstance iPrinter) {
- int border_top_left_y = top_left_y;
-
-
- drawHorizontalSeparator(iPrinter, top_left_x, bottom_right_x);
- }
- }
|