以编程方式将XPS文件打印到物理打印机 [英] Programmatically print an XPS file to a physical printer

查看:605
本文介绍了以编程方式将XPS文件打印到物理打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#WinForms应用程序.用户上载.XPS文件并指定一些打印机设置(份数,纸盒等). 程序需要使用这些设置以编程方式打印文档.即,没有用户交互要打印.

I have a C# WinForms application. A user uploads an .XPS file and specifies some printer settings (number of copies, paper tray, etc). The program needs to programmatically print the document with these settings. That is, there can be no user interaction to print.

我可以接近System.Printing AddJob方法. ( https://docs.microsoft.com/zh-CN/dotnet/framework/wpf/advanced/how-to-programmatically-print-xps-files ).但是,我无法在此处定义特定的设置,例如纸张来源,份数等.

I can come close with the System.Printing AddJob method. (https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/how-to-programmatically-print-xps-files). However, I can't define specific settings here, like paper source, number of copies, etc.

我更喜欢使用PrintDocument方法,但是我不知道如何获取PrintDocument来渲染/打印XPS文档.

I would prefer to use the PrintDocument method but I can't figure out how to get PrintDocument to render/print an XPS document.

我已经查看了该资源

I've looked at this resource, https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage(v=vs.110).aspx, but can't see how I can get the PrintPageEventHandler to render the XPS document.

关于如何进行的任何想法?帮助将不胜感激!

Any ideas on how I could proceed? Help would be greatly appreciated!

C#.NET 4.5

C# .NET 4.5

更新:

基于以下答案,我可以在添加作业时发送PrintTicket,如下所示:

Based on the below answer, I can send a PrintTicket when I add the job, like this:

 PrintTicket pt = printQueue.DefaultPrintTicket;
 pt.CopyCount = 2;
 // pt.InputBin = [ InputBin enum option ]
 printQueue.AddJob("name", "file", false, pt);

我看不到任何简单的方法来为PrintTicket设置InputBin. InputBin是一个枚举,没有选择仅将其设置为可用垃圾箱之一的名称的选项.

I can't see any easy way to set the InputBin for the PrintTicket. InputBin is an enum and doesn't have an option for just setting as the name of one of the available bins.

推荐答案

您在使用AddJob的轨道上正确无误,但是您需要

You're on the right track with AddJob, however you need the version that accepts a PrintTicket. You will need to create a new PrintTicket using the user's settings - any values that are set to null will end up using the defaults set for that PrintQueue.

这篇关于以编程方式将XPS文件打印到物理打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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