public static byte[] CreateScaleRasterReceiptData(Emulation emulation, LocalizeReceipt localizeReceipt, int width, bool bothScale, bool receipt, bool info, bool qrCode)
        {
            Bitmap image = localizeReceipt.CreateScaleRasterReceiptImage();

            byte[] urlData = SMCSAllReceipts.UploadBitmap(image);

            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            if (receipt)
            {
                builder.AppendBitmap(image, false, width, bothScale);
            }

            byte[] allReceiptsData;
            if (emulation == Emulation.StarGraphic)
            {
                allReceiptsData = SMCSAllReceipts.GenerateAllReceipts(urlData, emulation, info, qrCode, width); // Support to centering in Star Graphic.
            }
            else
            {
                allReceiptsData = SMCSAllReceipts.GenerateAllReceipts(urlData, emulation, info, qrCode);// Non support to centering in Star Graphic.
            }

            builder.AppendRaw(allReceiptsData);

            builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            builder.EndDocument();

            return(builder.Commands);
        }
Exemple #2
0
        public static byte[] CreateCouponData(StarIoExtEmulation emulation, LocalizeReceipts.ILocalizeReceipts localizeReceipts, int width, BitmapConverterRotation rotation)
        {
            Stream stream = localizeReceipts.CreateCouponImage();

            ICommandBuilder commandBuilder = Extension.CreateCommandBuilder(emulation);

            commandBuilder.BeginDocument();

            commandBuilder.AppendBitmap(stream, false, width, true, rotation);

            commandBuilder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            commandBuilder.EndDocument();

            return(commandBuilder.Commands);
        }
Exemple #3
0
        public async static Task <byte[]> CreateScaleRasterReceiptData(StarIoExtEmulation emulation, LocalizeReceipts.ILocalizeReceipts localizeReceipts, int width, bool bothScale)
        {
            Stream stream = await localizeReceipts.CreateScaleRasterReceiptImageAsync();

            ICommandBuilder commandBuilder = Extension.CreateCommandBuilder(emulation);

            commandBuilder.BeginDocument();

            commandBuilder.AppendBitmap(stream, false, width, bothScale);

            commandBuilder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            commandBuilder.EndDocument();

            return(commandBuilder.Commands);
        }
Exemple #4
0
        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.EndDocument();

            return(builder.Commands);
        }
Exemple #5
0
        public static byte[] CreateScaleRasterReceiptData(Emulation emulation, LocalizeReceipt localizeReceipt, int width, bool bothScale)
        {
            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            Bitmap rasterImage = localizeReceipt.CreateScaleRasterReceiptImage();

            builder.AppendBitmap(rasterImage, false, width, bothScale);

            builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            builder.EndDocument();

            return(builder.Commands);
        }
Exemple #6
0
        public static byte[] CreateFileOpenData(Emulation emulation, string filePath, int paperSize)
        {
            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            Bitmap rasterImage = (Bitmap)Image.FromFile(filePath);

            builder.AppendBitmap(rasterImage, true, paperSize, true);

            builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            builder.EndDocument();

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

            builder.BeginDocument();

            Bitmap rasterImage = localizeReceipt.CreateRasterReceiptImage();

            builder.AppendBitmap(rasterImage, false);

            builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            builder.AppendPeripheral(PeripheralChannel.No1);

            builder.EndDocument();

            return(builder.Commands);
        }
        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);
        }
Exemple #10
0
        public static byte[] CreateBitmapData(Emulation emulation, int width)
        {
            Bitmap sphereImage;

            using (var stream = Properties.Resources.sphere_image)
            {
                sphereImage = new Bitmap(stream);
            }

            Bitmap starLogoImage;

            using (var stream = Properties.Resources.star_logo_image)
            {
                starLogoImage = new Bitmap(stream);
            }

            ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

            builder.BeginDocument();

            builder.Append(Encoding.UTF8.GetBytes("*diffusion:true*\n"));
            builder.AppendBitmap(sphereImage, true);
            builder.Append(Encoding.UTF8.GetBytes("\n*diffusion:false*\n"));
            builder.AppendBitmap(sphereImage, false);

            builder.Append(Encoding.UTF8.GetBytes("\n*Normal*\n"));
            builder.AppendBitmap(starLogoImage, true);

            builder.Append(Encoding.UTF8.GetBytes("\n*width:Full, bothScale:true*\n"));
            builder.AppendBitmap(starLogoImage, true, width, true);
            builder.Append(Encoding.UTF8.GetBytes("\n*width:Full, bothScale:false*\n"));
            builder.AppendBitmap(starLogoImage, true, width, false);

            builder.Append(Encoding.UTF8.GetBytes("\n*Right90*\n"));
            builder.AppendBitmap(starLogoImage, true, BitmapConverterRotation.Right90);
            builder.Append(Encoding.UTF8.GetBytes("\n*Rotate180*\n"));
            builder.AppendBitmap(starLogoImage, true, BitmapConverterRotation.Rotate180);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Left90*\n"));
            //builder.AppendBitmap(starLogoImage, true, BitmapConverterRotation.Left90);

            builder.Append(Encoding.UTF8.GetBytes("\n*Normal,    AbsolutePosition:40*\n"));
            builder.AppendBitmapWithAbsolutePosition(starLogoImage, true, 40);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Right90,   AbsolutePosition:40*\n"));
            //builder.AppendBitmapWithAbsolutePosition(starLogoImage, true, BitmapConverterRotation.Right90, 40);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Rotate180, AbsolutePosition:40*\n"));
            //builder.AppendBitmapWithAbsolutePosition(starLogoImage, true, BitmapConverterRotation.Rotate180, 40);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Left90,    AbsolutePosition:40*\n"));
            //builder.AppendBitmapWithAbsolutePosition(starLogoImage, true, BitmapConverterRotation.Left90, 40);

            builder.Append(Encoding.UTF8.GetBytes("\n*Normal,    Alignment:Center*\n"));
            builder.AppendBitmapWithAlignment(starLogoImage, true, AlignmentPosition.Center);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Right90,   Alignment:Center*\n"));
            //builder.AppendBitmapWithAlignment(starLogoImage, true, BitmapConverterRotation.Right90, AlignmentPosition.Center);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Rotate180, Alignment:Center*\n"));
            //builder.AppendBitmapWithAlignment(starLogoImage, true, BitmapConverterRotation.Rotate180, AlignmentPosition.Center);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Left90,    Alignment:Center*\n"));
            //builder.AppendBitmapWithAlignment(starLogoImage, true, BitmapConverterRotation.Left90, AlignmentPosition.Center);

            builder.Append(Encoding.UTF8.GetBytes("\n*Normal,    Alignment:Right*\n"));
            builder.AppendBitmapWithAlignment(starLogoImage, true, AlignmentPosition.Right);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Right90,   Alignment:Right*\n"));
            //builder.AppendBitmapWithAlignment(starLogoImage, true, BitmapConverterRotation.Right90, AlignmentPosition.Right);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Rotate180, Alignment:Right*\n"));
            //builder.AppendBitmapWithAlignment(starLogoImage, true, BitmapConverterRotation.Rotate180, AlignmentPosition.Right);
            //builder.Append(Encoding.UTF8.GetBytes("\n*Left90,    Alignment:Right*\n"));
            //builder.AppendBitmapWithAlignment(starLogoImage, true, BitmapConverterRotation.Left90, AlignmentPosition.Right);

            builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);

            builder.EndDocument();

            return(builder.Commands);
        }