1

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?

Gabe
  • 84,912
  • 12
  • 139
  • 238
wham12
  • 295
  • 5
  • 21

4 Answers4

0

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
Victor Sanchez
  • 583
  • 9
  • 28
0

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.)

PowerUser
  • 11,583
  • 20
  • 64
  • 98
  • I run into the same issue sending it to a PDF as I do when I allow it to be generated in the .NET report viewer (which I believe processes it into a PDF to display). It does keep the correct font, but the barcodes I've added to the report are not processed correctly. One barcode displays incorrectly and the other two don't even show up at all. – wham12 Jul 15 '10 at 13:30
0

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.

wham12
  • 295
  • 5
  • 21
0

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"
Til
  • 5,150
  • 13
  • 26
  • 34
Usman
  • 1
  • 1