通过 Paginator 保存和打印 XPSDocument(似乎)会导致内容光栅化

发布于 2024-07-29 16:06:52 字数 1461 浏览 10 评论 0原文

我使用 WPF 打印路径来处理在我们的应用程序中创建的大型图表。 整个图表由视觉效果组成。

所谓的“DesignerPaginator”对图表进行分页(非常简单)。 从这一点出发,我做了以下三件事: - 我用 PrintDialog.PrintDocument(Paginator, Title) 打印文档 - 我还使用 XpsDocumentWriter.Write(Paginator, PrintTicket) 创建 XPS 文档; 我保存在硬盘上 - 从 XPSDocument 中,我将 XpsDocumentWriter.GetFixedDocumentSequence() 分配给 DocumentViewer

简而言之,以下代码很重要:

PrintDialog _pdialog = new PrintDialog();
System.Printing.ValidationResult result = this.PrintQueue.MergeAndValidatePrintTicket(this.PrintQueue.UserPrintTicket, this.PrintTicket);

_pdialog.PrintTicket = result.ValidatedPrintTicket;
XpsDocument _xpsDocument = new XpsDocument("C:\\test.xps",FileAccess.ReadWrite);
XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);
xpsdw.Write(this.Paginator, result.ValidatedPrintTicket);
documentviewer.Document = _xpsDocument.GetFixedDocumentSequence();
_xpsDocument.Close();

_pdialog.PrintQueue = this.PrintQueue;
_pdialog.PrintDocument(this.Paginator, "Model Test");

输出如下:

HDD 上的 XPS -> 绝对模糊。 你什么也认不出来。 它就像放大 100 倍的 GIF 文件。 DocumentViewer 中 XPSDocument 中的固定文档序列 -> 完美的。 这应该就是 XPS 文件的含义 打印输出-> 可怕,模糊,但至少比 xps 文件好得多

现在是神秘的部分:如果我直接从 DocumentViewer 打印(其中固定文档序列似乎很完美),我会从第一次打印中得到相同的模糊输出。

我对这种情况的想法是,WPF 的 XPS 系统对内容进行光栅化,并将这些内容作为低质量位图放置在 xps 文档中。 它都是矢量,尽管如此,输出对于低分辨率位图来说总是很熟悉。

我将不胜感激任何帮助。 我没主意了。 我尝试了很多方法来调试这个问题,但不知何故,它似​​乎既简单又微妙。

I use the WPF Printing Path to handle big large diagrams created in our application. The whole diagram consists of visuals.

A so called "DesignerPaginator" paginates the diagram (it is quite simple).
From this point, I do the following three thing:
- I print the Document with PrintDialog.PrintDocument(Paginator, Title)
- I also create a XPS Document with XpsDocumentWriter.Write(Paginator, PrintTicket); which I save on the HDD
- From the XPSDocument I assign XpsDocumentWriter.GetFixedDocumentSequence() to a DocumentViewer

In a nutshell, following code is important:

PrintDialog _pdialog = new PrintDialog();
System.Printing.ValidationResult result = this.PrintQueue.MergeAndValidatePrintTicket(this.PrintQueue.UserPrintTicket, this.PrintTicket);

_pdialog.PrintTicket = result.ValidatedPrintTicket;
XpsDocument _xpsDocument = new XpsDocument("C:\\test.xps",FileAccess.ReadWrite);
XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);
xpsdw.Write(this.Paginator, result.ValidatedPrintTicket);
documentviewer.Document = _xpsDocument.GetFixedDocumentSequence();
_xpsDocument.Close();

_pdialog.PrintQueue = this.PrintQueue;
_pdialog.PrintDocument(this.Paginator, "Model Test");

The output is the following:

XPS on HDD -> absolutely blurry. You can't recognize anything. It's like a GIF File with a 100x Zoom.
FixedDocumentSequence from the XPSDocument in the DocumentViewer -> Perfect. This should be what the XPS File is meant to be
Print output -> Horrible, blurry, but at least much better than the xps file

And now the mysterious part: If I print directly from the DocumentViewer (in which the FixedDocumentSequence seems perfect), I get the same blurry output from the first print.

My thought about this case is that the WPF's XPS System rasterize the content and place the stuff as low quality Bitmap within the xps Document. It's all vectors, and despite this fact the output always seems familiar to a low resolution bitmap.

I would appreciate any help. I'm out of ideas. I tried a lot to debug this problem, but it somehow seems to be something simple and delicate at the same time.

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

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

发布评论

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

评论(1

青春有你 2024-08-05 16:06:52

我找到了如何避免我的问题,但我不能保证该解决方案也适用于您的问题。
事实上,似乎使用两个嵌套的 VisualBrush 投影在您的 Visual 上,您正在使用模糊输出的结果。

我们在 wpf 打印中使用的一种 VisualBrush 是不可避免的:它是通过我们的分页器应用的一种,用于剪切视觉并将其分布到多个页面上。
我还有一个用作“模板”的用户控件。 我使用图表的 VisualBrush 在 UserControl 中绘制一个矩形,在此操作之后,用户控件本身将通过分页器使用 VisualBrush 将其自身绘制为矩形。
由于 WPF 的打印路径使用 XPS 进行打印,因此您还可以创建 XPSDocument,将文件类型更改为 zip,将其解压并使用任何文本编辑器分析文档的一页。
这将极大地帮助您理解您的问题。

我还怀疑,当 VisualBrush 的内容未应用 Visual 的原始 1:1 高/宽比时,文档会被“光栅化”。
调整大小计算中的错误导致所应用的 VisualBrush 的高度/宽度比为 1:0.9948,从而导致输出模糊(不包括“嵌套 VisualBrush”问题)。

这仍然只是一个怀疑。 我的问题已通过排除“额外”VisualBrush 并尊重原始宽高比得到解决。 还可以假设一个/或两个问题仅与特定视觉/效果/变换甚至 LinearBrush 结合出现。

至少,在涉及此类问题时,我了解到有关 WPF 打印路径的一件事:想想这样一个事实:您的内容总是在幕后转换为 xps,而 xps 与 wpf 类似,但不支持 wpf 所做的任何操作。 事实上,如果我没有理解错的话,XPS 是 WPF 中 XAML 的灵感来源。

我也非常欢迎对此问题的任何真正答案。 我的问题解决了,但我想知道为什么会发生这种情况。

I found out how to avoid my problem, but I can't guarantee the solution also applies to yours.
In fact, it seems that using two nested VisualBrushes projected on your Visual you are using results in the blurry output.

One VisualBrush we use in wpf printing cannot be avoided: it is the one that is applied through our Paginator to cut the Visual and distribute it onto multiple pages.
I also had one UserControl that served as "Template". I draw a Rectangle with the VisualBrush of our diagram into the UserControl, and after this operation the UserControl itself is draw itself as Rectangle with a VisualBrush onto the pages by the paginator.
Since WPF's printing path uses XPS for printing, you can also create an XPSDocument, change the file type to zip, extract it and analyse one page of your document with any text editor.
This will greatly help you understand your problem.

I also suspect that the document is "rasterized" when the content of the VisualBrush isn't applied with the original 1:1 height/width ratio the Visual has.
Errors within a resizing calculation led to a 1:0.9948 Height/Width Ratio for the applied VisualBrush, and this led to a blurry output (excluding the "nested VisualBrush" problem).

This is still just a suspicion. My problem has been solved by excluding the "extra" VisualBrush and respecting the original aspect ratio. It is also possible to assume that one /or both problems only appear in combination with a certain Visual/Effect/Transformation or even LinearBrushes.

At least, I learned one thing about the WPF Printing Path when it comes to such issues: Think of the fact that your stuff always gets converted to xps behind the scene, and xps is similar to wpf, but doesn't support anything wpf does. In fact, If I didn't missunderstood it, XPS was the inspiration for XAML in WPF.

I would also greatly welcome any real answer to this problem. My problem is solved, but I want to know why it did happen.

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