GetPrintCapabilities不会返回所有页面大小

Ant*_*ony 5 c# xml printing wpf

PrintCapabilities printCapabilites = SelectedPrinter.GetPrintCapabilities(); IEnumerable pagesizeList = printCapabilites.PageMediaSizeCapability;

上面的代码没有列出打印机驱动程序支持的所有页面大小,这是我的问题.

例如,如果您使用Microsoft XPS打印机驱动程序,您会发现pagesizeList(上面)将缺少某些页面大小."Letter Small"是缺少页面大小之一(MS Word将成功列出此页面大小).

作为快速检查,我将打印机功能转储到xml,如下所示:

long gpCLen = _selectedPrinter.GetPrintCapabilitiesAsXml().Length;
FileStream fs = File.OpenWrite(@"c:\test.txt");
MemoryStream ms = _selectedPrinter.GetPrintCapabilitiesAsXml();
byte[] b = new byte[gpCLen];
ms.Read(b, 0, (int)gpCLen);
fs.Write(b, 0, (int)gpCLen);
fs.Close();
Run Code Online (Sandbox Code Playgroud)

生成的xml文件中的PageMediaSize节点确实具有所有页面大小和缺少的页面大小.

显示的页面似乎有自己的名字开始psk:

<psf:Option name="psk:ISOA4" constrained="psk:None">
Run Code Online (Sandbox Code Playgroud)

但未显示的页面似乎有:

<psf:Option name="ns0000:LETTERSMALL" constrained="psk:None">
Run Code Online (Sandbox Code Playgroud)

未显示的Epson打印驱动程序页面类似:

<psf:Option name="epns200:IndexCard5x8" constrained="psk:None">
Run Code Online (Sandbox Code Playgroud)

基本上一个页面的名称开始'psk'PageMediaSizeCapability显示,但如果它是制造自定义,即epns200,ns0000,它不会列出.任何想法为什么以及如何解决这个问题?节点/页面在那里,但PageMediaSizeCapability不喜欢它!

提前致谢

编辑:

作为MS状态'A PrintCapabilities对象是一种易于使用的表示某种类型的XML文档,称为PrintCapabilities文档.但该文档的信息比对象完整描述更多

小智 3

您必须保存从 PrintCapability xml 中读取的纸张名称,并使用它来创建 PrintTicket xml(PrintTicket 有一个接受 xml 流的构造函数),然后使用 PrintTicket。以下是 PrintTicket XML 的示例(ns0000:User0000000257 是我创建的自定义纸张尺寸的名称):

    <psf:PrintTicket xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
           xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords"
           xmlns:ns0000="http://schemas.microsoft.com/windows/printing/oemdriverpt/Samsung_CLP-310 Series/5.1.2600.2180/" version="1">
  <psf:Feature name="psk:PageMediaSize">
    <psf:Option name="ns0000:User0000000257"></psf:Option>
  </psf:Feature>
</psf:PrintTicket>
Run Code Online (Sandbox Code Playgroud)