I'm trying to write an app that prints periodically. I've developed the app and I tested it with my HP Photosmart B110a printer and everything works fine, but on this next printer, which is a Lexmark MS621 I don't get anything back from PrintQueue. Why is that? Am I missing something?
To boil it down, this is the code that has to work.
//PDFtoPrinter documentation: https://github.com/svishnevsky/PDFtoPrinter
static void Print()
{
using (LocalPrintServer printServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer))
{
using (PrintQueue queue = new PrintQueue(printServer, printServer.DefaultPrintQueue.Name, PrintSystemDesiredAccess.AdministratePrinter))
{
//Start printing
new PDFtoPrinterPrinter().Print(new PrintingOptions(printServer.DefaultPrintQueue.Name, @"C:\Pdf\blank.pdf")).GetAwaiter().GetResult();
queue.Refresh(); //Just to make sure I refresh the queue
if (queue.NumberOfJobs > 1) //On my HP printer this if statement returns true after I started printing, but on the Lexmark it says there is no printjob even tho it started to print!
Console.WriteLine("There is a job!");
foreach (PrintSystemJobInfo info in queue.GetPrintJobInfoCollection()) //I've tried to print out all JobInfo on the printer, on the HP I get one, but on Lexmark I get 0
Console.WriteLine(info.Name);
PrintSystemJobInfo jobInfo = queue.GetPrintJobInfoCollection().FirstOrDefault(x => x.Name.Equals("blank.pdf")); //Get the jobInfo of the current file that I'm trying to print. Again, on HP I get the jobInfo but on the Lexmark I get nothing.
if (queue.IsOutOfPaper) //When I start to print without the printer having any paper this line on the HP returns true, but on the Lexmark it's alwaysfalse.
Console.WriteLine("There is no paper!");
if(jobInfo.IsPaperOut) //Same problem...
Console.WriteLine("There is no paper!");
}
}
}
One additional information.
The HP one is a network printer, the Lexmark one is connected via USB and I printed a test page with both.
Of course the driver is different, but the driver type too!
The Lexmark one is type 3
while the HP is type 4
, maybe this has to do something with the way this works?
Any help would be greatly appreciated!