public static byte[] CreateFeedData(Emulation emulation) { byte[] data = Encoding.UTF8.GetBytes("Hello World."); byte[] dataWithLf = Encoding.UTF8.GetBytes("Hello World.\n"); ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation); builder.BeginDocument(); builder.Append(data); builder.AppendLineFeed(); builder.AppendLineFeed(data); builder.Append(data); builder.AppendLineFeed(2); builder.AppendLineFeed(data, 2); builder.Append(data); builder.AppendUnitFeed(64); builder.AppendUnitFeed(data, 64); builder.Append(dataWithLf); builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed); builder.EndDocument(); return(builder.Commands); }
public static byte[] CreateQrCodeData(Emulation emulation) { byte[] data; data = Encoding.UTF8.GetBytes("Hello World.\n"); ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation); builder.BeginDocument(); builder.Append(Encoding.UTF8.GetBytes("*Cell:2*\n")); builder.AppendQrCode(data, QrCodeModel.No2, QrCodeLevel.L, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Cell:8*\n")); builder.AppendQrCode(data, QrCodeModel.No2, QrCodeLevel.L, 8); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Level:L*\n")); builder.AppendQrCode(data, QrCodeModel.No2, QrCodeLevel.L, 4); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Level:M*\n")); builder.AppendQrCode(data, QrCodeModel.No2, QrCodeLevel.M, 4); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Level:Q*\n")); builder.AppendQrCode(data, QrCodeModel.No2, QrCodeLevel.Q, 4); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Level:H*\n")); builder.AppendQrCode(data, QrCodeModel.No2, QrCodeLevel.H, 4); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*AbsolutePosition:40*\n")); builder.AppendQrCodeWithAbsolutePosition(data, QrCodeModel.No2, QrCodeLevel.L, 4, 40); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Alignment:Center*\n")); builder.AppendQrCodeWithAlignment(data, QrCodeModel.No2, QrCodeLevel.L, 4, AlignmentPosition.Center); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Alignment:Right*\n")); builder.AppendQrCodeWithAlignment(data, QrCodeModel.No2, QrCodeLevel.L, 4, AlignmentPosition.Right); builder.AppendUnitFeed(32); builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed); builder.EndDocument(); return(builder.Commands); }
public void AppendTextLabelData(ICommandBuilder commandBuilder, bool utf8) { Encoding encoding; if (utf8) { encoding = Encoding.UTF8; commandBuilder.AppendCodePage(CodePageType.UTF8); } else { // encoding = Encoding.ASCII; encoding = Encoding.UTF8; commandBuilder.AppendCodePage(CodePageType.CP998); } commandBuilder.AppendInternational(InternationalType.USA); commandBuilder.AppendCharacterSpace(0); commandBuilder.AppendUnitFeed(20 * 2); commandBuilder.AppendMultipleHeight(2); commandBuilder.Append(encoding.GetBytes("Star Micronics America, Inc.")); commandBuilder.AppendUnitFeed(64); commandBuilder.Append(encoding.GetBytes("65 Clyde Road Suite G")); commandBuilder.AppendUnitFeed(64); commandBuilder.Append(encoding.GetBytes("Somerset, NJ 08873-9997 U.S.A")); commandBuilder.AppendUnitFeed(64); commandBuilder.AppendMultipleHeight(1); }
public override void AppendTextLabelData(ICommandBuilder builder, bool utf8) { string encoding; if (utf8) { encoding = "UTF-8"; builder.AppendCodePage(CodePageType.UTF8); } else { encoding = "Shift_JIS"; builder.AppendCodePage(CodePageType.CP932); } builder.AppendInternational(InternationalType.Japan); builder.AppendCharacterSpace(0); builder.AppendUnitFeed(20 * 2); builder.AppendMultipleHeight(2); builder.Append(Encoding.GetEncoding(encoding).GetBytes("〒422-8654")); builder.AppendUnitFeed(64); builder.Append(Encoding.GetEncoding(encoding).GetBytes("静岡県静岡市駿河区中吉田20番10号")); builder.AppendUnitFeed(64); builder.Append(Encoding.GetEncoding(encoding).GetBytes("スター精密株式会社")); builder.AppendUnitFeed(64); builder.AppendMultipleHeight(1); }
public override void AppendTextLabelData(ICommandBuilder builder, bool utf8) { string encoding; if (utf8) { encoding = "UTF-8"; builder.AppendCodePage(CodePageType.UTF8); } else { encoding = "ASCII"; builder.AppendCodePage(CodePageType.CP998); } builder.AppendInternational(InternationalType.USA); builder.AppendCharacterSpace(0); builder.AppendUnitFeed(20 * 2); builder.AppendMultipleHeight(2); builder.Append(Encoding.GetEncoding(encoding).GetBytes("Star Micronics America, Inc.")); builder.AppendUnitFeed(64); builder.Append(Encoding.GetEncoding(encoding).GetBytes("65 Clyde Road Suite G")); builder.AppendUnitFeed(64); builder.Append(Encoding.GetEncoding(encoding).GetBytes("Somerset, NJ 08873-3485 U.S.A")); builder.AppendUnitFeed(64); builder.AppendMultipleHeight(1); }
public static byte[] CreateBitmapDataDetail(Emulation emulation) { ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation); builder.BeginDocument(); String BitmapTitle; Font TitleFont; Bitmap rasterImage; String BitmapDetail; BitmapTitle = "交易明細\n"; TitleFont = new Font("新細明體", 40); rasterImage = CreateBitmapFromString(BitmapTitle, 96.0F, 96.0F, TitleFont, 96); builder.AppendBitmap(rasterImage, false); String DateTime = " " + dr["printtime"] + "\n\n"; Font DateTimeFont = new Font("新細明體", 20); Bitmap rasterImage3 = CreateBitmapFromString(DateTime, 96.0F, 96.0F, DateTimeFont, 0); builder.AppendBitmap(rasterImage3, false); Font DetailFont = new Font("新細明體", 18); string subtitle = "品名/數量\t單價\t金額"; string subtitleWithSpace = CalculateSpaceWidth(subtitle, DetailFont, 96.0F, 96.0F, 20); BitmapDetail = subtitleWithSpace + "\n"; foreach (string productlist in products) { string[] lines = productlist.Split('\n'); foreach (string line in lines) { string productWithSpace = CalculateSpaceWidth(line, DetailFont, 96.0F, 96.0F, 20); BitmapDetail += productWithSpace + "\n"; } } Bitmap rasterImage4 = CreateBitmapFromString(BitmapDetail, 96.0F, 96.0F, DetailFont, 0, true); builder.AppendBitmap(rasterImage4, false); String total = "\n總計:" + new string(' ', 10) + dr["total"] + " 元\n"; Font totalFont = new Font("新細明體", 18); Bitmap rasterImage5 = CreateBitmapFromString(total, 96.0F, 96.0F, totalFont, 0, false); builder.AppendBitmap(rasterImage5, false); builder.AppendUnitFeed(5); builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed); builder.AppendPeripheral(PeripheralChannel.No1); builder.EndDocument(); return(builder.Commands); }
public static byte[] CreateBitmapData(Emulation emulation) { ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation); builder.BeginDocument(); string logoFile = appPath + @"\" + dr["logo"]; Bitmap logo = (Bitmap)Bitmap.FromFile(logoFile); Bitmap newImage = ResizeBitmap(logo, 400, 66); builder.AppendBitmap(newImage, false); builder.AppendUnitFeed(16); String BitmapTitle; Font TitleFont; Bitmap rasterImage; if (dr["atttext"] != "") { BitmapTitle = "電子發票證明聯補印\n"; TitleFont = new Font("新細明體", 36); rasterImage = CreateBitmapFromString(BitmapTitle, 92.0F, 96.0F, TitleFont, -8); } else { BitmapTitle = "電子發票證明聯\n"; TitleFont = new Font("新細明體", 40); rasterImage = CreateBitmapFromString(BitmapTitle, 96.0F, 96.0F, TitleFont, 0); } builder.AppendBitmap(rasterImage, false); String InvoiceTitle = " " + dr["year"] + "年" + dr["months"] + "月" + "\n"; InvoiceTitle += " " + dr["invoice"] + "\n"; Font InvoiceTitleFont = new Font("新細明體", 40, FontStyle.Bold); Bitmap rasterImage2 = CreateBitmapFromString(InvoiceTitle, 96.0F, 96.0F, InvoiceTitleFont, 0); builder.AppendBitmap(rasterImage2, false); //格式 String DateTime = " " + dr["printtime"] + " "; if (dr["fixtext"] != "") { DateTime += "格式 " + dr["fixtext"] + "\n"; } else { DateTime += "\n"; } Font DateTimeFont = new Font("新細明體", 20); Bitmap rasterImage3 = CreateBitmapFromString(DateTime, 96.0F, 96.0F, DateTimeFont, 0); builder.AppendBitmap(rasterImage3, false); String Random_Total = " 隨機碼 " + dr["randcode"] + " "; Random_Total += "總計 " + dr["total"] + "\n"; Font Random_TotalFont = new Font("新細明體", 20); Bitmap rasterImage4 = CreateBitmapFromString(Random_Total, 96.0F, 96.0F, Random_TotalFont, 0); builder.AppendBitmap(rasterImage4, false); String Seller_Buyer = " 賣方 " + dr["sellerid"] + " "; if (dr["byerid"] != "0000000000") { Seller_Buyer += "買方 " + dr["byerid"] + "\n"; } else { Seller_Buyer += "\n"; } Font Seller_BuyerFont = new Font("新細明體", 20); Bitmap rasterImage5 = CreateBitmapFromString(Seller_Buyer, 96.0F, 96.0F, Seller_BuyerFont, 0); builder.AppendBitmap(rasterImage5, false); builder.AppendUnitFeed(5); Image c39Img = GetCode39(dr["barcode"], 50); //計算條碼寬度產生的比例(會依照印表機DPI值變化) //可列印寬度(兩側留白0.3以上) = 5.7 - (0.3 * 2) = 5.1cm float ItoC = 2.54f; float dpiX = (float)200; float dpiY = (float)200; float widthlimit = (5.7f / ItoC) * dpiX; float rate = 0f; float newWidth = 0f; do { rate++; newWidth = c39Img.Width * rate; } while ((c39Img.Width * (rate + 1.0f)) <= widthlimit); //計算X定位點(條碼置中) float newX = (((5.7f / ItoC) * dpiX) / 2.0f) - (newWidth / 2.0f); Bitmap mybmp1 = new Bitmap((int)newWidth, 60); Graphics gr1 = Graphics.FromImage(mybmp1); gr1.DrawImage(c39Img, new Point[] { new Point(0, 0), new Point((int)newWidth, 0), new Point(0, c39Img.Height) }); gr1.Dispose(); builder.AppendBitmap(mybmp1, false); //QR碼 //利用matrix來計算產生QR碼的實際Size(去白邊) var hints = new Dictionary <EncodeHintType, object> { { EncodeHintType.CHARACTER_SET, "UTF-8" }, { EncodeHintType.QR_VERSION, 8 } }; var matrix = new MultiFormatWriter().encode(dr["qrcode1"], BarcodeFormat.QR_CODE, 140, 140, hints); var matrix2 = new MultiFormatWriter().encode(dr["qrcode2"], BarcodeFormat.QR_CODE, 140, 140, hints); matrix = CutWhiteBorder(matrix); matrix2 = CutWhiteBorder(matrix2); //把QR碼實際Size給BarcodeWriter參考產生 var qr1Writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new QrCodeEncodingOptions { Height = matrix.Height, Width = matrix.Width, CharacterSet = "utf-8", Margin = 0, ErrorCorrection = ErrorCorrectionLevel.L, QrVersion = 8 } }; var qr2Writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new QrCodeEncodingOptions { Height = matrix2.Height, Width = matrix2.Width, CharacterSet = "utf-8", Margin = 0, ErrorCorrection = ErrorCorrectionLevel.L, QrVersion = 8 } }; //QR碼至此產生的大小為不含白邊的原圖大小 Image qr1Img = qr1Writer.Write(dr["qrcode1"]); Image qr2Img = qr2Writer.Write(dr["qrcode2"]); Bitmap mybmp = new Bitmap(600, 180); Graphics gr = Graphics.FromImage(mybmp); //處理第一張圖片 gr.DrawImage(qr1Img, new Point[] { new Point(0, 0), new Point(140, 0), new Point(0, 140) }); gr.DrawImage(qr2Img, new Point[] { new Point(204, 0), new Point(344, 0), new Point(204, 140) }); //處理第二張圖片 gr.Dispose(); builder.AppendBitmapWithAbsolutePosition(mybmp, false, 30); // 打統編要接著印交易明細 if (dr["byerid"] == "0000000000") { builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed); } builder.AppendPeripheral(PeripheralChannel.No1); builder.EndDocument(); return(builder.Commands); }
public static byte[] CreatePdf417Data(Emulation emulation) { byte[] data; data = Encoding.UTF8.GetBytes("Hello World.\n"); ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation); builder.BeginDocument(); builder.Append(Encoding.UTF8.GetBytes("\n*Module:2*\n")); builder.AppendPdf417(data, 0, 1, Pdf417Level.ECC0, 2, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Module:4*\n")); builder.AppendPdf417(data, 0, 1, Pdf417Level.ECC0, 4, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Column:2*\n")); builder.AppendPdf417(data, 0, 2, Pdf417Level.ECC0, 2, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Column:4*\n")); builder.AppendPdf417(data, 0, 4, Pdf417Level.ECC0, 2, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Line:10*\n")); builder.AppendPdf417(data, 10, 0, Pdf417Level.ECC0, 2, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Line:40*\n")); builder.AppendPdf417(data, 40, 0, Pdf417Level.ECC0, 2, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Level:ECC0*\n")); builder.AppendPdf417(data, 0, 7, Pdf417Level.ECC0, 2, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Level:ECC8*\n")); builder.AppendPdf417(data, 0, 7, Pdf417Level.ECC8, 2, 2); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*AbsolutePosition:40*\n")); builder.AppendPdf417WithAbsolutePosition(data, 0, 1, Pdf417Level.ECC0, 2, 2, 40); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Alignment:Center*\n")); builder.AppendPdf417WithAlignment(data, 0, 1, Pdf417Level.ECC0, 2, 2, AlignmentPosition.Center); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Alignment:Right*\n")); builder.AppendPdf417WithAlignment(data, 0, 1, Pdf417Level.ECC0, 2, 2, AlignmentPosition.Right); builder.AppendUnitFeed(32); builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed); builder.EndDocument(); return(builder.Commands); }
public static byte[] CreateBarcodeData(Emulation emulation) { byte[] dataUpcE = Encoding.UTF8.GetBytes("01234500006"); byte[] dataUpcA = Encoding.UTF8.GetBytes("01234567890"); byte[] dataJan8 = Encoding.UTF8.GetBytes("0123456"); byte[] dataJan13 = Encoding.UTF8.GetBytes("012345678901"); byte[] dataCode39 = Encoding.UTF8.GetBytes("0123456789"); byte[] dataItf = Encoding.UTF8.GetBytes("0123456789"); byte[] dataCode128 = Encoding.UTF8.GetBytes("{B0123456789"); byte[] dataCode93 = Encoding.UTF8.GetBytes("0123456789"); byte[] dataNw7 = Encoding.UTF8.GetBytes("A0123456789B"); ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation); builder.BeginDocument(); builder.Append(Encoding.UTF8.GetBytes("*UPCE*\n")); builder.AppendBarcode(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*UPCA*\n")); builder.AppendBarcode(dataUpcA, BarcodeSymbology.UPCA, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*JAN8*\n")); builder.AppendBarcode(dataJan8, BarcodeSymbology.JAN8, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*JAN13*\n")); builder.AppendBarcode(dataJan13, BarcodeSymbology.JAN13, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Code39*\n")); builder.AppendBarcode(dataCode39, BarcodeSymbology.Code39, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*ITF*\n")); builder.AppendBarcode(dataItf, BarcodeSymbology.ITF, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Code128*\n")); builder.AppendBarcode(dataCode128, BarcodeSymbology.Code128, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Code93*\n")); builder.AppendBarcode(dataCode93, BarcodeSymbology.Code93, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*NW7*\n")); builder.AppendBarcode(dataNw7, BarcodeSymbology.NW7, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*HRI:NO*\n")); builder.AppendBarcode(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode1, 40, false); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Mode:1*\n")); builder.AppendBarcode(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode1, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Mode:2*\n")); builder.AppendBarcode(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode2, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("*Mode:3*\n")); builder.AppendBarcode(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode3, 40, true); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*AbsolutePosition:40*\n")); builder.AppendBarcodeWithAbsolutePosition(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode1, 40, true, 40); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Alignment:Center*\n")); builder.AppendBarcodeWithAlignment(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode1, 40, true, AlignmentPosition.Center); builder.AppendUnitFeed(32); builder.Append(Encoding.UTF8.GetBytes("\n*Alignment:Right*\n")); builder.AppendBarcodeWithAlignment(dataUpcE, BarcodeSymbology.UPCE, BarcodeWidth.Mode1, 40, true, AlignmentPosition.Right); builder.AppendUnitFeed(32); builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed); builder.EndDocument(); return(builder.Commands); }