XPS 有什么意义?

发布于 2024-08-19 23:21:55 字数 541 浏览 12 评论 0原文

当我阅读有关 WPF 的书籍时,我看到作者提到 XPS,就像它很重要一样。 Windows 还包括它的 XPS 查看器,我已经看到它被列为 Windows 的一项“功能”。

但为什么?有什么意义?到底谁用它?据我了解,XPS 基本上就像 PDF、xhtml 或 ePub(只是 xhtml)...甚至是 Word 的 docx 格式。这些格式的许多功能都是相同的。

与任何其他格式相比,它似乎没有任何重大优势。在我看来,xhtml 作为从 RichTextBox 保存和加载 FlowDocument 的方法,比 XPS 有用得多。我看过多个关于两者之间转换的博客。互联网上的大部分或全部富文本都是 (x)html。除此之外,我认为没有人只是用它来发布他们的文档;优先选择 PDF。看起来 XPS 只是 MS 制作并决定推出的某种随机格式。我一般都很喜欢MS,但他们确实有这种习惯。 MS 不能用 xhtml 制作一个 api 吗?我认为这在很多情况下会更有用。

那么,使用 XPS 有什么意义,特别是与我提到的其他格式之一(或我没有提到的任何格式)相比?您是否曾在您的程序或其他程序中使用过 XPS?

When I read books about WPF, I saw the authors mention XPS like it was something important. Windows also includes its XPS viewer, and I've seen that listed as a "feature" of Windows.

But why? What's the point? Who the heck uses it? It's my understanding that XPS is, basically, like PDF, xhtml, or ePub (which is just xhtml)...or even Word's docx format. Many of the features are the same among those formats.

It doesn't seem to have any major benefits compared to any of those other formats. It seems to me that xhtml would be so much more useful than XPS as a way to save and load FlowDocuments from the RichTextBox. I've looked at multiple blogs about converting between the two. Most or all of the rich text on the internet is (x)html. Beyond that, I don't think anyone uses it just to publish their docs; PDF is preferred. It seems like XPS is just some random format that MS made and decided to push. I generally love MS, but they do have a habit of that kind of thing. Couldn't MS have made an api using xhtml instead? That would have been more useful in a lot of situations, I'd think.

So, is there a point to using XPS, particularly in comparison to one of the other formats I mentioned (or any I haven't)? Have you ever used XPS in your programs or otherwise?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

魂ガ小子 2024-08-26 23:21:56

正如 U62 已经指出的,WPF 附带了一个 DocumentViewer 控件,使您能够查看 XPS 文档。 DocumentViewer 还具有一些有用的功能,如打印、缩放、FitToPage 等...因此您无需实现这些功能或使用第三方工具。

一小时前我刚刚使用 XPS 和 DocumentViewer 完成了某种“地址标签打印预览”。允许用户从联系人列表中选择一些联系人,单击“打印预览”。这将打开一个新的 XAML 窗口,其中包含一个 DocumentViewer 控件和一个可以选择不同标签的列表框(例如,1 个工作表包含 12 个标签 [2 列,6 行],1 个工作表包含单个标签,其宽度和高度可以由用户定义) 。
根据用户的选择,我在用户选择的布局中生成一个 XPS 文档,其中包含所选联系人的地址。例如,如果用户选择了 4 个联系人并希望将它们打印在“SingleLabelSheet”上,我会生成 1 个包含 4 页的 XPS 文档,每页包含 1 个地址。然后我在 DocumentViewer 中显示 XPS,用户可以在我们的标签打印机上打印标签。

一旦我了解了 XPS API 的工作原理(至少是基础知识),只需 2 个小时即可启动并运行它。

因此,基本上,我将 XPS 视为一种易于使用的 API,用于显示动态生成的固定文档。但我个人不会将它们保存到我的硬盘上或以某种方式修改它们或您通常对文档执行的任何操作。

As U62 already stated, WPF comes with a DocumentViewer control which enables you to view XPS documents. The DocumentViewer also has some useful fonctions like Print, Zoom, FitToPage etc... So you don't need to implement that or use a third party tool.

What I just finished an hour ago using XPS and the DocumentViewer was some kind of "Adress label print preview". Allow the user to select some contacts from a list of contacts, click "Print Preview". This opens a new XAML Window which contains a DocumentViewer control and a ListBox with the choice of different Labels (e.g. 1 sheet with 12 labels [2 columns, 6 rows], 1 sheet with a single label whose width and height can be user defined).
Based on the users selection, I generate an XPS Document in the layout the user selected with the adresses of the selected contacts. If e.g. the user selected 4 contacts and wishes to print them on "SingleLabelSheet"'s, I generate 1 XPS document with 4 pages, each page containing 1 Adress. Then I display the XPS in the DocumentViewer and the user can print the labels on our Label Printer.

Once I understood how the XPS API worked (at least the Basics), it was a matter of 2 hours to get this up and running.

So, basically, I see XPS as an easy to use API to display FixedDocuments which are to be generated on the fly. But I wouldn't personnally go about saving them to my HDD or somehow modify them or whatever you generally do with documents.

焚却相思 2024-08-26 23:21:56

我能想到的唯一实际优点是您可以在 WPF 应用程序中控制查看 XPS 文档。您提到的其他格式意味着您必须引入第三方渲染器(或者如果您有一年的空闲时间,您可以自己编写一个渲染器)。

顺便提一句。我对 ePub 了解不多,但 XPS 不能直接与 XHTML 相比较,它更像 PDF,因为它被设计为具有固定布局。

The only actual advantage I can think of is that you have a control for viewing XPS documents in WPF applications. The other formats you mention mean you would have to bring in a 3rd party renderer (or write one yourself if you have a year to spare).

btw. I don't know much about ePub, but XPS isn't directly comparable with XHTML, it's more like PDF in that it's designed to have a fixed layout.

提笔落墨 2024-08-26 23:21:56

XPS 到 WPF 就像 WMF 到 Win32/WinForms 一样,它是一种持久格式,可让您存储和打印本机 WPF 图形。

XPS 用于从 WPF 进行打印(即使您直接从应用程序打印而不保存,内部打印系统也是基于 XPS 构建的),所以 MS 应该做什么:

  1. 创建一个与他们想要执行的操作完全匹配的新文件
  2. 格式从 WPF 到 PDF 等他们无法控制的格式的 100% 完美转换器(希望 Adob​​e 不会在下一版 Acrobat Reader 中破坏所有 WPF 应用程序)。

你会怎么办?

保存 XPS 文件只是一个不错的奖励。

XPS to WPF is like WMF to Win32/WinForms, it's a persistent format that let you store and print native WPF graphics.

XPS is used to print from WPF (even when you print directly from the application without saving, the internal printing system is built on XPS) so what should MS do:

  1. Create a new file format that exactly fit with what they are trying to do
  2. Build a 100% perfect translator from WPF to a format they don't control like PDF (and hope Adobe doesn't break all WPF applications out there with the next release of Acrobat Reader).

What would you do?

Saving XPS files is just a nice bonus.

看海 2024-08-26 23:21:56

看,我可能对 XPS 作为报告生成解决方案持悲观态度,但我尝试了一下,发现最初的文档很难理解,现实世界中的样本比我想要的要少。当我将其放入现实世界的业务应用程序中时,我发现它令人沮丧,特别是在需要跨多个页面的表的 LOB 应用程序中。

从那时起,事情可能已经发生了变化,但当我开始查看跨越几页的表格时,我希望列标题位于顶部,等等。我发现 API 要求我做我称之为过多的解决方法,并带来不必要的麻烦。复杂。

所以,从那时起(大约 8 个月前),情况可能发生了变化,但我从 XPS 转向使用 ITextSharp,这已经减轻了很多痛苦。

因此,像其他人一样,我想说的唯一优点是 WPF 中的内置查看器 - 但除此之外,我觉得 API 可能需要“成熟”一点,然后我才会再次尝试其中的某些内容。

Look, I may be a pessimist on XPS as a report generation solution, but I gave it a go and found the initial documentation to be hard to understand, with less real world samples out there than what I would have liked. When I put it into a real world business application I found it to be frustrating, particularly in LOB apps that require tables that span over multiple pages.

Things may have changed since then but as soon as I started looking at tables that spanned over several pages and I wanted column headers to go to the top, etc. I found that the API required me to do what I would call excessive workarounds with unnecessary complexity.

So, things may have changed since then (about 8 months ago), but I went from XPS to using ITextSharp and that has been a lot less painful.

So the only advantage I would say, like everyone else, is the built in viewer in WPF - but other than that I feel the API may need to "mature" a bit more before I will attempt something again in it.

鹿港小镇 2024-08-26 23:21:56

事实上,我找到了使用 XPS 的一个非常好的理由。我想从多个来源打印,合并文档 并指定双面打印和装订。最后应将其打印为一份双面打印并装订的文档。我在这样做时遇到了困难,但发现通过打印到 XPS(保存到光盘)我可以轻松实现我的目标。我还没有发现任何其他方法如此简单和直接。

    Dim PrintServer As New SysPrint.PrintServer("\\" & My.Computer.Name)
    Dim PrintQ As New SysPrint.PrintQueue(PrintServer, "Ricoh Main")
    Dim Jobs As SysPrint.PrintJobInfoCollection = PrintQ.GetPrintJobInfoCollection
    Dim able As SysPrint.PrintCapabilities = PrintQ.GetPrintCapabilities()

    Dim CurrentTicket As SysPrint.PrintTicket = PrintQ.CurrentJobSettings.CurrentPrintTicket
    If able.StaplingCapability IsNot Nothing AndAlso able.StaplingCapability.Count > 0 Then
        If able.StaplingCapability.Contains(Printing.Stapling.StapleTopLeft) Then
            CurrentTicket.Stapling = Printing.Stapling.StapleTopLeft
        End If
    Else
        Debug.Print("no stapling capability")
    End If

    CurrentTicket.Duplexing = Printing.Duplexing.TwoSidedLongEdge

    Dim fiName As String = "S:\Temp\PS\XPS\Test.xps"

    Dim TestJob As SysPrint.PrintSystemJobInfo _
            = PrintQ.AddJob("Test job", fiName, False)

Actually I found a really nice reason to use XPS. I wanted to print from multiple sources, merge documents and specify duplex and stapled. Finally it should be printed as one document with duplex and stapled. I was having a difficult time doing so but found that by printing to XPS (saved to disc) I could accomplish my goal with minimum fuss. I haven't found any other method that is so easy and straightforward.

    Dim PrintServer As New SysPrint.PrintServer("\\" & My.Computer.Name)
    Dim PrintQ As New SysPrint.PrintQueue(PrintServer, "Ricoh Main")
    Dim Jobs As SysPrint.PrintJobInfoCollection = PrintQ.GetPrintJobInfoCollection
    Dim able As SysPrint.PrintCapabilities = PrintQ.GetPrintCapabilities()

    Dim CurrentTicket As SysPrint.PrintTicket = PrintQ.CurrentJobSettings.CurrentPrintTicket
    If able.StaplingCapability IsNot Nothing AndAlso able.StaplingCapability.Count > 0 Then
        If able.StaplingCapability.Contains(Printing.Stapling.StapleTopLeft) Then
            CurrentTicket.Stapling = Printing.Stapling.StapleTopLeft
        End If
    Else
        Debug.Print("no stapling capability")
    End If

    CurrentTicket.Duplexing = Printing.Duplexing.TwoSidedLongEdge

    Dim fiName As String = "S:\Temp\PS\XPS\Test.xps"

    Dim TestJob As SysPrint.PrintSystemJobInfo _
            = PrintQ.AddJob("Test job", fiName, False)
夏至、离别 2024-08-26 23:21:56

XPS(代号“metro”)显然是作为 Windows Vista 中 PDF 和 PostScript 的 Microsoft 替代品而设计的。请参阅此处的旧文章:Microsoft 准备新文档打印规范

XPS (code named "metro") was clearly designed as the Microsoft alternative to PDF and PostScript in Windows Vista. See this old article here: Microsoft Readies New Document Printing Specification

望笑 2024-08-26 23:21:56

发明文档格式时有不同的方法:

  • 有些是为了在屏幕上快速查看(例如低清晰度)而设计的,例如 HTML、doc。
  • 其他一些(或可能)非常尊重打印限制(例如基于质量),例如 PDF、XPS。

XPS 与 PDF 一样好,而且它是 XML 格式的,所以“也许”它比 PDF 中的流方法更标准。

XPS的黑点可能是对特殊颜色(Pantone、纸张效果)的管理。

There are different approches when inventing document formats:

  • Some are made for quick view on screen (say low def) like HTML, doc.
  • Some other are (or can be) very respectuous of printing contrains (say quality based) like PDF, XPS.

So XPS whiches to be as good as PDF, plus it is formated in XML, so "maybe" it is more standard than the stream approch in PDF.

The black spot of XPS is maybe the management of special colors (Pantone, paper effects).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文