cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot print B&W with Crystal Reports API

10-01-2015 11:56 AM
1072 views 9 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

I am unable to print black and white using Crystal reports .NET object model.

I am using 'Cute PDF' printing driver which is able to print B&W/color correctly using Windows API directly (with DEVMODE/dmColor+dmFields).  Trying to do the same via Crystal does not work. Two attempts have been made:

  1. using SetDevMode (PrinterSettings::SetHdevmode() and PageSettings::SetHdevmode() with DEVMODE structure filled as in case of direct Windows API direct call)
  2. using PrinterSettings/PageSettings Color field

None of these seem to work and the report is printed in color regardless of parameters set.

Powershell script used for test:

#load the assemblies

[reflection.assembly]::LoadWithPartialName('System.Drawing.Printing')

[reflection.assembly]::LoadWithPartialName('CrystalDecisions.Shared')

[reflection.assembly]::LoadWithPartialName('CrystalDecisions.CrystalReports.Engine')

$ReportLocation = "C:\Test\chequereport.rpt"

$PrinterName = "CutePDF Writer"

#setup Crystal Document object

$Report = New-Object CrystalDecisions.CrystalReports.Engine.ReportDocument

#load the Crystal Report

$Report

.Load($ReportLocation)

#create the required printer and page settings

$PrintOptions = New-Object System.Drawing.Printing.PrinterSettings

$PageOptions = New-Object System.Drawing.Printing.PageSettings

#add the desired printer or it will print to the default printer

$PrintOptions.PrinterName = $PrinterName

$PrintOptions.Copies = 1

$PageOptions.Color = $false

$PrintOptions.DefaultPageSettings.Color = $false

#print

$Report.PrintToPrinter($PrintOptions, $PageOptions, $false)

$Report.Dispose()

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Hi Don,

We've tried your code (added in btnPOController_Click_1 handler) and it does not generate any error on POC printing. We are using Cute PDF PDF printer driver for testing purposes - not a real printer; and it does support color/B&W rendering.

We are trying to find a way to tell POC to print in B&W but it does not have any Color field to set anywhere via property or method (probably should be present in CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions but there is none) so I guess there is no way to print in B&W this way. On the other hand, in P2P we can easily set System.Drawing.Printing.PageSettings.Color = false and System.Drawing.Printing.PrinterSettings.DefaultPageSettings.Color = false but they are ignored anyway during the rpt.PrintToPrinter(printerSettings, pSettings, false, PrintLayout) call.

Arek.

0 Likes

Hi Arek,

I finally have time to do more testing and I am getting the same results as you.

POC has no color option and P2P ignores it when I set it also.....

But this may be because the IT department configures our printers and we install the drivers to the network share.... I don't have admin rights to make any changes to the printer settings so P2P changes will be ignored.

All I can suggest now is you have 2 printers defined on their PC's, one for Color and one for black and white and then select the appropriate one at runtime. Or save the report with the printer COL or BW, you can do that by opening the report in CR Designer and click the Print button. Make the changes and click Apply and then cancel. Then save the report, this saves the printer set up in the RPT file.

Don

PS - I'll ask DEV if we can add a color property to POC and ask if P2P color property should work.

Former Member
0 Likes

Hi Don,

Thank you for your answer and investigation of this problem. The provided workaround work for us for now.

Best regards,

Arek.

P.S.

Could you provide us a replay from your DEV team if color property should work and if it is possible to add color to POC in the future.

0 Likes

If the system does not allow changing color settings nothing CR can do.

Only option is to have 2 drivers in the list, one with color and one without...

Don

Answers (1)

Answers (1)

0 Likes

Hi Arek,

Download SP 15 and set the Viewers Print button to use the PrintOutPutController and see if that works for you.

If you are not using CR for VS then need more info.

Don

Former Member
0 Likes

Hi Don,

Thank you for your fast answer, but it didn't resolve our problem. We are using Crystal runtime for VS with printer settings saved in local execution instance (as DEVMODE structure) which might be different than global/default printer settings. PrintOutPutController seems to respect printer global settings only and there is no way to tell it to print in B&W (regardless of printer global settings, which would be in color by default). It would be ideal if it could respect printing settings passed via Crystal Reports 'SetHDevMode()' for the current document or some other method but it looks like there is none. Printer settings passed to PrintOutPutController::PrintReport method do not have any 'Color' field to set. The only workaround for now is to change default printer settings to B&W.

Arek.

0 Likes

Hi Arek,

CR for .NET does not use nor can it use DEVMODEW structure. It's .NET framework, it has no access to that structure ( directly )...

CR for .NET uses this:

System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();

CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();

System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();

Search for KBA 2163438, I attached a Printer test app to it, see if that works for you.

And if the Printer allows access to the Color mode you can set it, may be the issue is your app does not have access to that property?

Don

Former Member
0 Likes

Hi Don,

OK. So to summarize. We've tried your application with the following results:

  1. Using CrystalReportsViewer (by clicking Print button and setting printer properties to 'Black & White'):
    • we can print in B&W correctly via PrintOutputController
    • P2P can print in color only
  2. Using code:
    • no other way to print in B&W than changing default/global printer setting to 'Black & White' and use PrintOutputController
    • P2P can print in color only (even if we set printerSettings.DefaultPageSettings.Color = false; and pSettings.Color = false;  )

The P2P printing code in your application is similar to our Powershell test script.

So it seems like neither P2P nor POController allows to do it programmatically.  Or perhaps there is some workaround for POController as it works fine via CrystalReportsViewer +PrintOutputController? Is there any property that can be passed to CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions that can force Black & White printing?

Arek.

0 Likes

Hi Erek,

It's not always CR causing the issue. Does your IT department allow changing the setting? It could be read only and/or not allowed...

See what happens when you add this to my test app in the POC section:

try // set the color to be true

{

pDoc.PrinterSettings.DefaultPageSettings.Color = true;

catch (Exception ex)

{

    MessageBox.Show("ERROR: " + ex.Message);

    return;

}

Our printers here also support color but our IT Department do not allow me to change the setting at runtime. They created a separate printer install that does support color, so everyone by default does not print in color, it's get expensive for black and white pages...

Don