我已经创建了一个ActiveX控件,其中包含处理打印机(星形TSP100)的所有方法,如实例化、打开打印机等。该ActiveX正在com中注册。当我通过javascript使用打印机方法时,除了PrintBarCode和PrintBitmap方法和抛出错误之外,所有的方法都工作得很好。
对于我使用过的位图:
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的调试模式下工作。但是在创建安装程序并将其安装到系统中之后,这两个程序就不能工作了。
错误是:-
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发布于 2012-10-12 22:48:11
我也有同样的问题,对于位图,我有一个解决方法:
printer.PrintBitmap(PrinterStation.Receipt, path, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);可能打印机无法缩放位图。但由于在将位图发送到打印机之前很容易缩放,我认为这是一个很好的解决方法。
对于条形码问题,我只能说,我使用了错误的BarCodeSymbology (Ean13S而不是EanJan13)。如果我有进一步的见解,我会在这里分享。
发布于 2014-03-22 04:10:42
dlg:是否打开文件对话框
cbAlignment:包含三个值的组合框: Left、Center、Right。
tbWidth和tbWidth:适用于打印大小
cbTextPosition:用于文本位置
以下是屏幕截图:

我有Epson-T20,代码对我很好:
//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从来没有尝试过,对不起,如果我发现了什么,我会告诉你的,祝你们好运。
https://stackoverflow.com/questions/12708099
复制相似问题