Crystal Report .NET 字体更改

发布于 2024-09-09 07:55:43 字数 933 浏览 6 评论 0原文

我设计了一个水晶报告,它将通过网络界面发送到特定的(条形码)打印机。允许在标准水晶报表查看器中生成报表会导致问题,因此我现在使用隐藏代码将报表直接发送到打印机。

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 界面将作业发送到打印机(任何打印机)时,它会将字体更改为 Times New Roman,这会弄乱所有字段大小。如果我使用标准 .NET 报表查看器,它会使用正确的字体,因此我非常确定更改是由创建/使用 ReportDocument 引起的。

如何将报告直接发送到打印件而不将字体默认回 Times New Roman?

I've designed a crystal report that will be sent to a specific (barcode) printer through a web interface. Allowing the report to be generated in the standard crystal report viewer was causing issues, so I am now using the code-behind to send the report directly to the printer.

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();

When printed from the designer (CRXI) everything works fine but when the web interface sends the job to a printer (any printer) it changes the font to Times New Roman which messes up all of the field sizes. If I use the standard .NET report viewer it uses the correct font, so I'm pretty sure the change is being caused by creating/using the ReportDocument.

How can I send the report directly to a print without it defaulting the fonts back to Times New Roman?

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

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

发布评论

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

评论(4

泅渡 2024-09-16 07:55:43

我想到了这个想法:
如果您不直接将报告从 Crystal 发送到打印机,而是使用某种中间人,即先将 .rpt 导出为 .pdf,然后打印 PDF,会怎么样?

(是的,这将是一种非常“木桌”的方法,但如果它有效,它就有效。)

This idea occured to me:
Instead of sending the report straight from Crystal to the printer, what if you use some kind of middleman, i.e. export the .rpt to .pdf first, then print the PDF?

(Yes, it would be a very "wooden tables" tables approach, but if it works, it works.)

め七分饶幸 2024-09-16 07:55:43

虽然我使用的特殊字体似乎已经包含在每台可以想象到的服务器上,但我始终无法让它通过网络界面运行。
我最终找到了一种最适合该项目需求的标准 Windows 字体,并放弃了尝试解决这个问题。

While it seemed like the special font I was using had been included on every server imaginable, I was never able to get it to work through the web interface.
I ended up finding a standard windows font that mostly suited the needs of this project and have given up on trying to beat this problem.

黯淡〆 2024-09-16 07:55:43

您需要使用 RAS SDK API。 Visual Studio 2010 (v13) 的 Crystal Reports 包含此 api。 (此代码在 Visual Studio 2005 的 Crystal Reports 中不起作用...我没有有关其他版本的信息)

将此引用添加到您现有的代码中:

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

You need use RAS SDK API. Crystal Reports for Visual Studio 2010 (v13) include this api. (This code don't work in Crystal Reports for Visual Studio 2005... I don't have info about other versions)

Add this references to your existing code:

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

And use this code (VB... sorry)

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
请爱~陌生人 2024-09-16 07:55:43

我试图根据报告上显示的数据更改 Crystal Report 字体。
我使用 Formate Formula 使用标志 Condition 来更改字体。

if({?vIsRightToLeft}=true)then
"Attari Font"
Else
"Arial"

I was trying to change Crystal Report Font according to data that will be shown on the report.
I use Formate Formula to change the font using flags Condition.

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