Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9052

Re: No Printers are Installed - Printtoprinter problem from Scheduled Task

$
0
0

Don, thanks for your help.  I found out what the problem was.  This code below was not setting the printer.

 

crystalReport.PrintOptions.PrinterName = "\\\\print_server\\printer";

 

So, at the times I tested it where it printed successfully (either in debug mode of the project or when double-clicking the compiled executable file), it was just using the default printer for the currently logged-in user. 

 

I looked further and found the solution in this article: https://scn.sap.com/thread/2099449

 

Changing from this:

 

crystalReport.PrintOptions.PrinterName = "\\\\print_server\\printer";

crystalReport.PrintToPrinter(1, true, 0, 0);

 

to this:

 

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

printersettings.PrinterName = PrinterToUse;

printersettings.Copies = 1;

printersettings.Collate = false;

Report.PrintToPrinter(printersettings, new System.Drawing.Printing.PageSettings(), false);

 

resolved my issue.

 

For anyone else reading this, if using the code above you get the error:  "Settings to access printer are not valid."  Use this bit of code on the machine where you plan on running the program to get the list of valid printers (if you're making a console application):

 

foreach(string myPrinter in System.Drawing.Printing.PrinterSettings.InstalledPrinters){

    Console.WriteLine(myPrinter);

}

Console.ReadLine();


Viewing all articles
Browse latest Browse all 9052

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>