Silverlight 5打印乱码报告 [英] Silverlight 5 printing garbled Reports
问题描述
我使用C1ReportViewer控件,并已经在C1论坛上发布了一个问题,但我认为我会发布在这里,以查看是否有人遇到过类似的问题。该控件使用通用的silverlight PrintDocument()方法。
I am using a C1ReportViewer control, and have already posted a question on the C1 forums, however i thought i would post here as well to see if anyone had run across a similar issue. The control uses the generic silverlight PrintDocument() method.
在Silverlight 5中从此控件打印Crystal报表时,报表有时会显示乱码,线和一般不在位置。它也很少打印整个报告。
When printing a Crystal Report from this control in Silverlight 5 sometimes the report prints out garbled, meaning different sized text, tapered lines and generally out of position. It also rarely prints the entire report.
我已经将问题缩小到几个打印机,只有使用32位驱动程序的机器。基于这一点,以及对Silverlight 5的更改,我假设这个问题围绕着PostScript兼容性。然而,由于我们的产品是LOB应用程序,强制执行PS兼容的打印机和打印机驱动程序几乎是没有问题的。
I have narrowed the issue down to a few printers, and only with machines using their 32 bit drivers. Based upon this, and the changes made to Silverlight 5, i am assuming the issue revolves around PostScript compatibility. However, as our product is LOB application, enforcing PS compatible printers and printer drivers is nearly out of the question.
因此,如果这确实是一个后脚本问题,基于根据silverlight 5的文档,PrintDocument()方法应该失败回到默认位图方法。请参阅我是否正确要了解在SilverLight 5中的矢量打印只能使用Postscript打印机吗?
Accordingly, if this is indeed a post script issue, based upon the documentation for silverlight 5, the PrintDocument() method should be failing back to the default bitmap method. See Am I correct in understanding that vector printing in SilverLight 5 will only work with a Postscript printer?
我的stackoverflow问题是:有人遇到类似的问题,在Silverlight 5,或有任何人有成功打印水晶报表/ PDF?
My question for stackoverflow is: Has anyone encountered a similar issue in with printing in Silverlight 5, or has anyone had success printing Crystal Reports/PDFs? And in the off chance that anyone has, what solutions have you come up with?
很感激,
Greg
推荐答案
我能够想出一个解决方案。
I was able to come up with a solution for this. Instead of using the built in C1 Printing functionality I was able to write some code to force bitmap printing.
首先,我创建了一个新的PrintDocument,并挂接了一些处理程序为它的PrintPage事件。
First i created a new PrintDocument, and hooked up some handlers for its PrintPage event.
mobjPrintDocument = New PrintDocument
RemoveHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
AddHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
然后,无论何时打印,我们都可以在PrintDocument上调用PrintBitmap函数。这里我在用户点击打印按钮时这样做。
Then we can call the PrintBitmap function on the PrintDocument whenever you want to print. Here I am doing it when the user clicks the Print button.
Private Sub xbtnPrint_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
mintPageIndex = 0
mobjPrintDocument.PrintBitmap(FileName)
End Sub
现在是重要的部分。我们可以通过挂钩到PrintPage事件中来劫持目标内容(如上所述)。我可以设置e.PageVisual到任何视觉xaml元素,PrintBitmap将处理它。这里我使用GetPages函数和循环,以确保我打印每个页面(一个pdfviewer元素)。
Now comes the important part. We can hijack the content targeted by hooking into the PrintPage event (as handled above). I can set the e.PageVisual to any visual xaml element and the PrintBitmap will handle it. Here I use the GetPages function and loop through to make sure I print each page (a pdfviewer element). However, you can point it to any visual element like I said.
Private Sub Print_Report(sender As System.Object, e As PrintPageEventArgs)
e.PageVisual = xobjReportViewer.GetPages(mintPageIndex)
mintPageIndex += 1
e.HasMorePages = mintPageIndex < xobjReportViewer.GetPages.Count
End Sub
e.HasMorePages允许您强制
The e.HasMorePages allows you to force the firing of this event until you are finished.
希望这对某人有帮助。使用Silverlight 5和Post-Script打印机支持,许多具有PostScript仿真器的打印机可能不兼容,但也不会默认为位图打印。此解决方法修复了,使打印在LOB类型应用程序中更稳定。
Hope this is helpful to someone. With Silverlight 5 and the Post-Script printer support, alot of printers that have a PostScript emulator may not be compatible, but will also not default to bitmap printing. This workaround fixes that, making printing a little bit more stable in a LOB type application.
这篇关于Silverlight 5打印乱码报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!