RLubanovic
2007-08-11 18:10:01 UTC
Hi,
I have been trying to solve a batch printing issue for a few weeks. I
have tried numerous strategies and have posted a few questions. I have not
received any answers to this point. I will explain my latest strategy:
This is a VB.Net 2.0 app, and it uses C# for the printing object.
There is a difference between printing one invoice or a batch.
When I print one invoice, I can use the "open" verb and allow IE to
launch. This is nice because it allows the user to print preview, select the
printer and print. Then they close IE and return to the app.
When I want to print a batch, I can select the printer ahead of time, then
call IE in a loop with the "print" verb and expect to print them all using
the default printer.
The issue is that IE wants to prompt me for the printer every time. This
is not good.
I am attempting to redirect standard in to recieve the default printer
from a stream. In order to do this, I had to change the code to the
following snippett:
Process proc = new Process();
if (fPromptForPrinter)
{
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "open";
proc.StartInfo.FileName = strFileName;
}
else
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
proc.StartInfo.Verb = "print";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.FileName = "C:\\Program Files\\Internet
Explorer\\iexplore.exe";
proc.StartInfo.Arguments = strFileName;
}
proc.Start();
if (!fPromptForPrinter)
{
StreamWriter myStreamWriter = proc.StandardInput;
myStreamWriter.WriteLine(strDefaultPrinter);
myStreamWriter.Close();
//proc.WaitForExit();
proc.Close();
}
for (; ;)
{
if (proc.HasExited)
{
break;
}
else
{
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(1000);
}
}
In order to redirect standard in, I had to set UseShellExecute to false.
I believe this causes me to send IExplorer.exe as the filename with
arguments.
When I went this route, it appears that the print verb is ignored and that
IE is launched and will "open: the document. This is not good. I also tried
with the WindowStyle hidden and that was ignored.
So, is there any way to make this work as intended ? Is there a /P for
print (switch) or something that could be passed ?
Or is there another route that can solve this ? I have investigated other
strategies that don't use IE, but I have alot of time invested in getting the
HTML document just right and would like to work this out.
Thanks for the help.
Rick
P.S. I don't know what would be the best discussion group for this question.
I have been trying to solve a batch printing issue for a few weeks. I
have tried numerous strategies and have posted a few questions. I have not
received any answers to this point. I will explain my latest strategy:
This is a VB.Net 2.0 app, and it uses C# for the printing object.
There is a difference between printing one invoice or a batch.
When I print one invoice, I can use the "open" verb and allow IE to
launch. This is nice because it allows the user to print preview, select the
printer and print. Then they close IE and return to the app.
When I want to print a batch, I can select the printer ahead of time, then
call IE in a loop with the "print" verb and expect to print them all using
the default printer.
The issue is that IE wants to prompt me for the printer every time. This
is not good.
I am attempting to redirect standard in to recieve the default printer
from a stream. In order to do this, I had to change the code to the
following snippett:
Process proc = new Process();
if (fPromptForPrinter)
{
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "open";
proc.StartInfo.FileName = strFileName;
}
else
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
proc.StartInfo.Verb = "print";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.FileName = "C:\\Program Files\\Internet
Explorer\\iexplore.exe";
proc.StartInfo.Arguments = strFileName;
}
proc.Start();
if (!fPromptForPrinter)
{
StreamWriter myStreamWriter = proc.StandardInput;
myStreamWriter.WriteLine(strDefaultPrinter);
myStreamWriter.Close();
//proc.WaitForExit();
proc.Close();
}
for (; ;)
{
if (proc.HasExited)
{
break;
}
else
{
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(1000);
}
}
In order to redirect standard in, I had to set UseShellExecute to false.
I believe this causes me to send IExplorer.exe as the filename with
arguments.
When I went this route, it appears that the print verb is ignored and that
IE is launched and will "open: the document. This is not good. I also tried
with the WindowStyle hidden and that was ignored.
So, is there any way to make this work as intended ? Is there a /P for
print (switch) or something that could be passed ?
Or is there another route that can solve this ? I have investigated other
strategies that don't use IE, but I have alot of time invested in getting the
HTML document just right and would like to work this out.
Thanks for the help.
Rick
P.S. I don't know what would be the best discussion group for this question.