当PrintNormal工作时,PosPrinter.PrintBarCode,PosPrinter.PrintBitmap不工作 [英] PosPrinter.PrintBarCode, PosPrinter.PrintBitmap is not working while PrintNormal is working

查看:103
本文介绍了当PrintNormal工作时,PosPrinter.PrintBarCode,PosPrinter.PrintBitmap不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个ActiveX控件,其中包含处理打印机(Star TSP100)的所有方法,例如实例化,打开打印机等。ActiveX正在com中注册。
当我通过javascript使用打印机方法时,除PrintBarCode和PrintBitmap方法外,所有方法均工作正常,并抛出错误。

I have created an ActiveX control which contains all the methods to handle a printer (Star TSP100) such as instantiating, Opening printer etc. The ActiveX is being registered in the com. When i am using printers methods through javascript, all methods are working fine except PrintBarCode and PrintBitmap method and throwing an error.

对于位图,我使用过:-

For bitmap i have used :-

printer.PrintBitmap(PrinterStation.Receipt, path, percentWidth * lineWidth / 100, PosPrinter.PrinterBitmapCenter);

和条形码:-

printer.PrintBarCode(PrinterStation.Receipt, code, BarCodeSymbology.Code93, 80, (int)(0.9 * lineWidth), PosPrinter.PrinterBarCodeCenter, BarCodeTextPosition.Below);

尽管这两种方法也可以在Visual Studio的调试模式下使用。但是在创建设置并在系统中安装后,这两个功能均无法使用。

Although these two methods are also working in debug mode from visual studio. but after creating the setup and installing in the system it these two are not working.

错误是:-

Microsoft.PointOfService.PosControlException: Method PrintBarCode threw an exception.  Attempt was made to perform an illegal or unsupported operation with the device, or an invalid parameter value was used.
   at Microsoft.PointOfService.Legacy.LegacyProxy.ThrowLegacyMethodException(String methodName, Int32 ResultCode, Exception e)
   at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethod(String methodName, Object[]& parameters, Boolean[] byRef)
   at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethodAndCheckImpl(String methodName, Object[]& parameters, Boolean[] byRef)
   at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethodAndCheckImpl(String methodName, Object[] parameters)
   at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethodAndCheck(String methodName, Object param1, Object param2, Object param3, Object param4, Object param5, Object param6, Object param7)
   at Microsoft.PointOfService.Legacy.LegacyPosPrinter.PrintBarCode(PrinterStation station, String data, BarCodeSymbology symbology, Int32 height, Int32 width, Int32 alignment, BarCodeTextPosition textPosition)
   at xyx.testclass.PrintBarCode(String code)
ErrorCode: Illegal
ErrorCodeExtended: 0


推荐答案

dlg :是打开文件对话框

cbAlignment :是包含三个值的组合框:Left,Center,Right。

cbAlignment : is Combobox containing the three values : Left, Center, Right.

tbWidth tbWidth :用于打印尺寸

cbTextPosition :对于文本位置

以下是屏幕截图:

我有 Epson-T20 ,代码对我来说很好:

i have Epson-T20, code works fine for me :

//In the loading of the form : to init cbTextPosition
cbTextPosition.Items.Clear();
cbTextPosition.Items.AddRange(Enum.GetNames(typeof (BarCodeTextPosition)));

要打印:

try
            {
                //Show the Open File Dialog Box
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "Image files|*.bmp;*.gif;*.jpg";

                //Try It First With Monochrome Bmp Image : try it with 384x384 px
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    //Init your stuff here
                    PosExplorer explorer;
                    DeviceInfo _device;
                    PosPrinter _oposPrinter;

                    explorer = new PosExplorer();
                    _device = explorer.GetDevice(DeviceType.PosPrinter, "T20PRINTER");

                    _oposPrinter = (PosPrinter) explorer.CreateInstance(_device);
                    _oposPrinter.Open();
                    if (!_oposPrinter.Claimed)
                    {
                        _oposPrinter.Claim(5000);
                        _oposPrinter.DeviceEnabled = true;
                        PrinterStation CurrentStation = PrinterStation.Receipt;

                        //This is a Header :
                        _oposPrinter.PrintNormal(PrinterStation.Receipt, "Here is your LOGO : ");

                        //Printing Your Logo :
                        int alignment; 
                        if (cbAlignment.Text == "Left")
                            alignment = PosPrinter.PrinterBarCodeLeft;
                        else if (cbAlignment.Text == "Center")
                            alignment = PosPrinter.PrinterBarCodeCenter;
                        else if (cbAlignment.Text == "Right")
                            alignment = PosPrinter.PrinterBarCodeRight;
                        else
                            alignment = int.Parse(cbAlignment.Text, System.Globalization.CultureInfo.CurrentCulture);

                        //Print it : you can try 384px for real size in tbWidth
                        _oposPrinter.PrintBitmap(
                            CurrentStation,
                            dlg.FileName,
                            int.Parse(tbWidth.Text, System.Globalization.CultureInfo.CurrentCulture),
                            alignment);

                        //Cutting your Paper :
                        _oposPrinter.CutPaper(95);
                    }

                }

            }
            catch (Exception c)
            {
                MessageBox.Show(c.Message);
            }

对于Codebar从未尝试过对不起,如果我发现有什么我会告诉你的,祝你好运。

For the Codebar never tried it sorry, if i find something i will tell you, good luck guys.

这篇关于当PrintNormal工作时,PosPrinter.PrintBarCode,PosPrinter.PrintBitmap不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆