cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Report 2016 with Visual Studio 2017 - Assigning PrinterName

0 Kudos

Don,

You have been resolving my crystal reports issues, Thank you.

Exporting of PDF, I had used the following line to get PDF generated. Instead of older code

rp.ExportToHttpResponse (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "reportname");

Older code which does not support the new crystal reports

//MemoryStream oStream; // using System.IO
//oStream = (MemoryStream)
//rp.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
//Response.Clear();
//Response.Buffer = true;
//Response.ContentType = "application/pdf";
//Response.BinaryWrite(oStream.ToArray());
//Response.End();

I am facing a new problem while setting the printer name dynamically fetching from table..

In one of the report the below mentioned code works perfect and goes to printer.

string str_printer = string.Empty;
str_printer = drtemp[0].ToString();
rp.PrintOptions.PrinterName = str_printer;
rp.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
rp.PrintOptions.PaperSize = PaperSize.PaperLetter;
rp.PrintToPrinter(1, true, 0, 0);

The above same code does not seem to work in another report, the str_printer names become empty.

I tried debugging the code. str_printer get the value "HPM651", when it passes the below line

rp.PrintOptions.PrinterName = str_printer;

it becomes empty.

Please let me know how to assign printer name, why is that the printer name getting empty only in the above case.

Thanks

Venkat

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Try my printer app, use a report with saved data:

https://blogs.sap.com/2015/08/19/printing-crystal-reports-in-net/

Don

Answers (6)

Answers (6)

0 Kudos

Don,

I don't understand why, when my client was using Crystalreport 2008, the same printtoprinter worked well. Now that he had moved to Windows 2012 R2 server and crystalreports 2016, the printing is getting so much delayed.

As suggested, I wanted to give a try to use

PrinterOutputController

My local machine: Windows 8.1; 32bit Crystal Reports 2016; Visual Studio 2017

CrystalDecisions.ReportAppServer.ReportDefModel

CrystalDecisions.ReportAppServer.Controllers

C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86

I was able to add the above reference to my project and was able to build it right.

CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions printReportOptions = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
CrystalDecisions.ReportAppServer.Controllers.PrintOutputController printOutputController = new CrystalDecisions.ReportAppServer.Controllers.PrintOutputController();
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings);
rp.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
rp.PrintOptions.PaperSize = PaperSize.PaperLetter;
rp.PrintOptions.PrinterDuplex = PrinterDuplex.Vertical;
rptClientDoc = rp.ReportClientDocument;
printReportOptions.PrinterName = "HP8150";                         
rptClientDoc.PrintOutputController.PrintReport(printReportOptions);

When I am trying the above source in client server location which is 2012 R2 server which is a 64bit which has got all Crystal reports 2016, visual studio 2017

The dll's where in a different location

CrystalDecisions.ReportAppServer.ReportDefModel

CrystalDecisions.ReportAppServer.Controllers

I could not build the application as the reference could not be sorted out error ; 'Controller' is inaccessible due to protection level.

Please let me know what needs to be done to resolve this issue

Thanks

Venkat

0 Kudos

Use POC to print always, much more control and uses CR runtime to do the printing. P2P uses the System printer only.

0 Kudos

Hello,

Thanks Jessica,

I tried the following method to sent the report to the printer, it worked.

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();
string str_printer = string.Empty;
str_printer = drtemp[0].ToString();
printerSettings.PrinterName = str_printer;                                                      
System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings);
rp.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;
rp.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
//rp.PrintOptions.PrinterDuplex = PrinterDuplex.Simplex;
rp.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);

However, I have not changed my previous code for all other reports

string str_printer = string.Empty;
str_printer = drtemp[0].ToString();
rp.PrintOptions.PrinterName = str_printer;
rp.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
rp.PrintOptions.PaperSize = PaperSize.PaperLetter;
rp.PrintOptions.PrinterDuplex = PrinterDuplex.Horizontal;
rp.PrintToPrinter(1, true, 0, 0);

Though the above code works well for printing, in some cases my client complains that the printer is getting smudged/paper is jammed and trying to print the job over and over again. Is there any solution for this?. Why is that the print job is getting repeated over and over gain.

Thanks

Venkat

Former Member
0 Kudos

Hi,

you need to add the appropriate reference.


Go to your solutionexplorer, select your project and navigate to references.
Press "Add Reference" and the reference-manager should open up.
Navigate to assemblies, choose extensions and mark "CrystalDecisions.ReportAppServer.Controllers"

Hope it helps.

Jessica

0 Kudos
error-controler.jpg

Don,

Thanks for your speedy response

I tried to make use of the below code to use PrintOutPutController instead of PrinttoPrinter.

System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions rasPROpts = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptionsClass();
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper rptClientDoc = new CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper();

 pDoc.PrinterSettings.PrinterName = "HPM651";
 rasPROpts.PrinterName = "HPM651";

rptClientDoc.PrintOutputController.PrintReport(rasPROpts);

Please refer the screen of the error attached.error-controler.jpg

Let me know your suggestions.

Thanks
Venkat
0 Kudos

Use the printer test app in this post:

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

You need to use PrintOutputController to do the printing.

Don