Silverlight 5 printing garbled Reports

可紊 提交于 2019-12-25 01:34:38

问题


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.

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.

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.

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?

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?

Much Appreciated,

Greg


回答1:


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.

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

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

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

The e.HasMorePages allows you to force the firing of this event until you are finished.

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.



来源:https://stackoverflow.com/questions/10114460/silverlight-5-printing-garbled-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!