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:
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
$Report.PrintToPrinter($PrintOptions, $PageOptions, $false)
$Report.Dispose()
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
Hi Don,
OK. So to summarize. We've tried your application with the following results:
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.
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
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.