views:

569

answers:

2

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.

A: 

Did you find any answer ? I have the same problem and no one seems to know the answer

ExistMe
+1  A: 

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.

Alex Maker