环境:
问题:我想打印生成的图片,但我不想为用户显示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获取它。有没有其他方法可以打印生成的图像?