I have an application that creates a file (it happens to be a PDF file, but my problem occurs with .DOCX and .XLSX files). After creating it, it sends it to your default printer. That's where it gets a little crazy.
If the default printer is a system network one, the printer starts immediately after the file is streamed to it. If it is a locally connected printer, the streaming is immediate, but the printer doesn't start up for several minutes.
To test the connectivity of the printer, I can separately open up the PDF with my default PDF reader and print it and it is instantaneous.
Another test I performed is printing via another application that uses the PrintDocument method and it is immediately printed. I don't know where the problem is, but this is my code that performs the streaming:
public static class myPrinters
{
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDefaultPrinter(string Name);
}
private string SendToPrinter ( string strFileName, string strPrinterName )
{
FileInfo f = new FileInfo ( strFileName );
string fullname = f.FullName;
byte[] file = File.ReadAllBytes ( fullname );
// This is my ideal scenario in case the user wants to print to a different printer.
// I have tried with this line commented out and get the same results.
//
myPrinters.SetDefaultPrinter( strPrinterName );
PrintQueue printQueue = LocalPrintServer.GetDefaultPrintQueue();
using (var job = printQueue.AddJob())
using (var stream = job.JobStream)
{
stream.Write ( file, 0, file.Length );
}
Thanks in advance,
Jerry
Jerry Scannell
If the default printer is a system network one, the printer starts immediately after the file is streamed to it. If it is a locally connected printer, the streaming is immediate, but the printer doesn't start up for several minutes.
To test the connectivity of the printer, I can separately open up the PDF with my default PDF reader and print it and it is instantaneous.
Another test I performed is printing via another application that uses the PrintDocument method and it is immediately printed. I don't know where the problem is, but this is my code that performs the streaming:
public static class myPrinters
{
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDefaultPrinter(string Name);
}
private string SendToPrinter ( string strFileName, string strPrinterName )
{
FileInfo f = new FileInfo ( strFileName );
string fullname = f.FullName;
byte[] file = File.ReadAllBytes ( fullname );
// This is my ideal scenario in case the user wants to print to a different printer.
// I have tried with this line commented out and get the same results.
//
myPrinters.SetDefaultPrinter( strPrinterName );
PrintQueue printQueue = LocalPrintServer.GetDefaultPrintQueue();
using (var job = printQueue.AddJob())
using (var stream = job.JobStream)
{
stream.Write ( file, 0, file.Length );
}
Thanks in advance,
Jerry
Jerry Scannell