1

I am writing a code in c# that prints PDF programmatically using printer drivers. Sometimes, it is shown a pop up that requires user input, e.g.

The toner is about to be exhausted, continue? YES - NO

and the printer doesn't print until the user clicks. This code runs on a server, so no one can go and click. Is there a way to overcome this problem, without knowing all the possible questions (different printers). I use this code to print, I block printing until previous document is printed:

process.StartInfo.FileName = filePath;
process.StartInfo.Arguments = "\"" + printerName + "\"";
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.Verb = "PrintTo";
process.Start();
var server = new PrintServer();

try
{
    int numberOfJobs = server.GetPrintQueue(printerName).NumberOfJobs;

    while (numberOfJobs == 0)
    {
        numberOfJobs = server.GetPrintQueue(printerName).NumberOfJobs;

    }
    while (numberOfJobs > 0)
    {
        numberOfJobs = server.GetPrintQueue(printerName).NumberOfJobs;
    }
    retVal = true;
}
catch
{
    retVal = false;
}
finally
{
    process.Kill();
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • See this : https://www.technipages.com/disable-windows-print-notification-balloon – PaulF Feb 21 '18 at 09:34
  • 2
    Why do you need to print using some process? There are methods to print directly in c#, look [here](https://stackoverflow.com/a/36432772/1997232). – Sinatr Feb 21 '18 at 09:38
  • The fact is using "Process", you're launching an external process, which does whatever it wants. See @Sinatr comment to avoid trying to print that way. – Kilazur Feb 21 '18 at 10:09
  • in the @Sinatr link, it is requested or Windows 10 or Microsoft.Office.Interop. It's not ok for me – Valentina Carella Feb 21 '18 at 10:29
  • @PaulF, it's not notification balloon, but a Dialog one that stops the printing until user clicks – Valentina Carella Feb 21 '18 at 10:31
  • *"it is requested or Windows 10 or Microsoft.Office.Interop"* - what? [PrintDocument](https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument(v=vs.110).aspx) exists from stone age. And it will output on the walls of your cave if needed... or what do you mean? – Sinatr Feb 21 '18 at 10:31
  • @Sinatr: as far as I understand the question Valentina is trying to print PDF files, not "Print To PDF" as your first link is showing. The issue is the Toner Low dialog that appears on the print server which needs operator attention before printing can take place. – PaulF Feb 21 '18 at 12:00

0 Answers0