Beispiel #1
0
        public static byte[] CreatePeripheralData(Emulation emulation)
        {
            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            builder.AppendPeripheral(PeripheralChannel.No1);
            builder.AppendPeripheral(PeripheralChannel.No2);
            builder.AppendPeripheral(PeripheralChannel.No1, 2000);
            builder.AppendPeripheral(PeripheralChannel.No2, 2000);

            builder.EndDocument();

            return(builder.Commands);
        }
Beispiel #2
0
        public static byte[] CreateData(Emulation emulation, PeripheralChannel channel)
        {
            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            builder.AppendPeripheral(channel);

            builder.EndDocument();

            return(builder.Commands);
        }
        public static byte[] CreateTextReceiptData(Emulation emulation, LocalizeReceipt localizeReceipt, bool utf8)
        {
            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            localizeReceipt.AppendTextReceiptData(builder, utf8);

            builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            builder.AppendPeripheral(PeripheralChannel.No1);

            builder.EndDocument();

            return(builder.Commands);
        }
        public static byte[] CreateCouponData(Emulation emulation, LocalizeReceipt localizeReceipt, int width, BitmapConverterRotation rotation)
        {
            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            Bitmap rasterImage = localizeReceipt.CreateCouponImage();

            builder.AppendBitmap(rasterImage, false, width, true, rotation);

            builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            builder.AppendPeripheral(PeripheralChannel.No1);

            builder.EndDocument();

            return(builder.Commands);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }