Reputation: 385
Here is how I print my flowdocument:
PrintDialog pd = new PrintDialog();
LocalPrintServer local = new LocalPrintServer();
PrintQueue pq = local.DefaultPrintQueue;//GetPrintQueue("[Printer Name]"); //e.g. local.GetPrintQueue("Microsoft XPS Document Writer");
pd.PrintQueue = pq;
PrintTicket pt = pq.DefaultPrintTicket;
pt.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA5);// or we can specify the custom size(width, height) here
pd.PrintTicket = pt;
pt.PageBorderless = PageBorderless.Borderless;
pt.PageOrientation = PageOrientation.ReversePortrait;
PrintCapabilities capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket);
double sizeWidth = capabilities.PageImageableArea.ExtentWidth;
double sizeHeight = capabilities.PageImageableArea.ExtentHeight;
var fd = new FlowDocument();
DocumentPaginator sd = ((IDocumentPaginatorSource)fd).DocumentPaginator;
sd.PageSize = new Size(sizeWidth + 20, sizeHeight);
pd.PrintDocument(sd, "My Doc");
// GET THE PRINTER STATUS IN MESSAGE BOX HERE..
MessageBox.Show(printerStatus()); // printerStatus() is a pseudo method to retrieve the status of the printer.
How can i get the current status of the printer so that it will output, Printing, Out of Paper, Paper jam, Printer Offline, etc message????
Upon searching, I came across this page: http://msdn.microsoft.com/en-us/library/system.printing.printqueuestatus.aspx
However I have no clue on it's usage. Can you any body help me to get in with it?
This print process is being running in a STA thread.
Upvotes: 1
Views: 3909
Reputation: 17691
you can check like this
using System.Management;
class PrinterOffline
{
private static void Main(string[] args)
{
// Set management scope
ManagementScope scope = new ManagementScope("\\root\\cimv2");
scope.Connect();
// Select Printers from WMI Object Collections
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
string printerName = "";
foreach (ManagementObject printer in searcher.Get())
{
printerName = printer("Name").ToString().ToLower();
if (printerName.Equals("Name_Of_Printer"))
{
Console.WriteLine("Printer = " + printer("Name"));
if (printer("WorkOffline").ToString().ToLower().Equals("true"))
{
// printer is offline by user
Console.WriteLine("Your Plug-N-Play printer is not connected.");
}
else
{
// printer is not offline
Console.WriteLine("Your Plug-N-Play printer is connected.");
}
}
}
}
}
pls go through this link for more information on status of the printer
Upvotes: 2