WPF C#在Zebra GK888t(ZDesigner)打印机中打印图像

时间:2015-08-03 17:53:01

标签: c# wpf printing zebra-printers printdialog

环境:

  • Zebra(ZDesigner)GK888t EPL标签打印机
  • 10cm x 5cm纸
  • Windows驱动程序(其他任何不起作用)
  • Windows打印机首选项中的已配置打印机选项
    • 纸张宽度:10cm
    • 纸张高度:5cm
    • 媒体设置:直接散热

问题:我想打印生成的图片,但我不想为用户显示PrintDialog。 用户只能通过按下按钮" PRINT"来打印图像,但我无法实现。

工作版 PrintDialog对话框:

Image image = new Image();

PrintDialog dlg = new PrintDialog();
bool? result = dlg.ShowDialog();

PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);

Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

image.Measure(sz);
image.Arrange(
    new Rect(
        new Point(
            capabilities.PageImageableArea.OriginWidth,
            capabilities.PageImageableArea.OriginHeight
        )
        ,sz
    )
);

dlg.PrintVisual(image, "Print a Large Image");

版本没有 PrintDialog对话框:

Image image = new Image();

PrintDialog dlg = new PrintDialog();
dlg.PageRange = new PageRange(1);
PrintQueue printQueue = new PrintServer()
                            .GetPrintQueues().ToList()
                            .FirstOrDefault(x => x.FullName.Contains("ZDesigner GK888t (EPL)"));
dlg.PrintQueue = printQueue;

PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);

Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

dlg.PrintTicket.PageMediaSize = new PageMediaSize(sz.Width, sz.Height);

image.Measure(sz);
image.Arrange(
    new Rect(
        new Point(
            capabilities.PageImageableArea.OriginWidth,
            capabilities.PageImageableArea.OriginHeight
        )
        ,sz
    )
);

dlg.PrintVisual(image, "Print a Large Image");

但是这段代码不起作用,Zebra打印机在这种情况下不打印,或打印空白标签,或停在标签中间并停止工作(闪烁红灯)

问题:如何解决?我认为它不能很好地工作,因为打印机的配置不适用(如纸张尺寸或介质设置 - 直接热选项),因为从PrintQueues获取它。有没有其他方法可以打印生成的图像?

0 个答案:

没有答案