2010-07-14 91 views
1

我設計了一個水晶報表,它將通過Web界面發送到特定的(條形碼)打印機。允許在標準水晶報表查看器中生成報表會導致問題,因此我現在使用代碼隱藏功能將報表直接發送到打印機。Crystal Report .NET字體變化

ReportDocument Report = new ReportDocument();      
ParameterDiscreteValue Order = new ParameterDiscreteValue(); 

Order.Value = Convert.ToInt32(txtOrder); 
Report.Load(reportPath); 
Report.SetParameterValue("OrderNo", Order); 

PageMargins margins; 
margins = Report.PrintOptions.PageMargins; 
margins.bottomMargin = 0; 
margins.leftMargin = 0; 
margins.rightMargin = 0; 
margins.topMargin = 0; 

Report.PrintOptions.ApplyPageMargins(margins); 
Report.PrintOptions.PrinterName = "\\\\printserver\\Zebra Z6M Plus (300dpi)";     
Report.PrintToPrinter(1, false, PageNum, PageNum); 

Report.Close(); 

當從設計師(CRXI)一切印刷工作正常,但當Web界面將作業發送到打印機(任何打印機),它改變了字體爲宋體這打亂了所有這些字段大小。如果我使用標準的.NET報表查看器,它使用正確的字體,所以我非常確定這個更改是由創建/使用ReportDocument引起的。

如何將報告直接發送至印刷品,而不將其默認爲Times New Roman字體?

+0

您的打印機驅動程序是否是最新的? – PowerUser 2010-07-15 13:08:16

+0

是的,我確保驅動程序是最新的,並且它確實能夠從Crystal設計器正常工作,而不是通過後面的.NET代碼。 – wham12 2010-07-15 13:31:26

回答

0

雖然它似乎像我用的是已被納入每個服務器上想象的特殊字體,我從來沒有能夠通過Web界面來實現它。 我最終找到了一個標準的windows字體,大多數都適合這個項目的需求,並且已經放棄了試圖解決這個問題。

0

這種想法發生在我:
而不是直接從水晶將報告發送給打印機,如果你使用某種類型的中間人,即出口.RPT第一爲.pdf,然後打印PDF?

(是的,這將是一個非常「木桌」表的做法,但如果它的工作原理,它的工作原理。)

+0

我遇到同樣的問題,將它發送到PDF,就像我在.NET報表查看器中生成它一樣(我相信它會將其處理爲PDF來顯示)。 它確實保留了正確的字體,但我添加到報表中的條形碼沒有正確處理。一個條形碼顯示不正確,另外兩個甚至不顯示。 – wham12 2010-07-15 13:30:25

0

您需要使用RAS SDK API。 Crystal Reports for Visual Studio 2010 (v13)包含此api。 (此代碼不能在Crystal Reports工作的Visual Studio 2005 ...我沒有關於其他版本信息)

添加此引用您的現有代碼:

CrystalDecisions.ReportAppServer.ClientDoc 
CrystalDecisions.ReportAppServer.Controllers 
CrystalDecisions.ReportAppServer.ReportDefModel 

,並使用此代碼(VB ...抱歉)

Using rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument 
    rpt.Load(file, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy) 
    rpt.SetDataSource(_ReportSource) 
    Dim options As New CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions 
    options.Collated = _Collate 
    options.NumberOfCopies = _Copies 
    ' TODO: Implement_startPageN and _endPageN 
    Dim optPrint As CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions 
    optPrint = rpt.ReportClientDocument.PrintOutputController.GetPrintOptions 
    optPrint.PrinterName = _PrinterName             rpt.ReportClientDocument.PrintOutputController.ModifyPrintOptions(optPrint) 
    rpt.ReportClientDocument.PrintOutputController.PrintReport(options) 
    rpt.Close() 
End Using