Reputation: 19
With this code:
PrintQueue pq;
using (var PS = new LocalPrintServer())
{
pq = PS.GetPrinterQueue("HP Printer");
}
pq.AddJob("JobName 1", "C:\\Resources\\basic.xps", true, pq.DefaultPrintTicket.Clone());
I can successfully print files with some printers queue, but not with all my printers queue and I got System.PrintJobException--Specified method is not supported. (The parameter PrintTicket here is by default, but I need this overload method in order to change this value).
Also PrintQueue.AddJob(string jobName, string filePath, bool fastCopy)
throws System.PrintJobException.
However using PrintQueue.AddJob(string jobName)
instead of PrintQueue.AddJob(string jobName, string filePath, bool fastCopy, PrintTicket printTicket)
it throws no exception, but the file to print cannot be specified.
Does every driver support the PrintQueue.AddJob()? Is anything missing?
Thanks a lot in advance.
I finally solved it using this instead of pq.AddJob()
:
pq.UserPrintTicket = pq.DefaultPrintTicket.Clone(); // Whatever PrintTicket we need
pq.Commit();
string s;
using (StreamReader strReader = new StreamReader("C:\\Resources\\basic.xps")){
s = strReader.ReadToEnd();
}
PrintDocument p = new PrintDocument();
p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};
p.Print();
Upvotes: 1
Views: 2418
Reputation: 36
Just set fastCopy = false
in PrintQueue.AddJob(string jobName, string filePath, bool fastCopy)
Upvotes: 1