Print any file to a specific printer (silently)

  • Thread starter Thread starter kaf
  • Start date Start date
K

kaf

Hi,

I have a requirement where I have to print any given file to a specific
printer. My application then consumes the output of this printer. I also
need to do this without any user intervention and without any GUI. I have
managed to get the printing done using Shell Execute, however, it always
shows the associated application even though I have specified
ProcessWindowStyle.Hidden as window style. My code snippets are given below:

<CODE>
Process objProcess = new Process();

objProcess.StartInfo.FileName = fileName; //file to print

objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden |
ProcessWindowStyle.Minimized;

objProcess.StartInfo.UseShellExecute = true;

objProcess.StartInfo.CreateNoWindow = false;

objProcess.StartInfo.ErrorDialog = false;

objProcess.StartInfo.Verb = "print";



objProcess.Start();

</CODE>

I have searched all over but no solutions so far. I also think that this
should be possible as Microsoft Fax service does exactly this using it's fax
printer.

Any pointers will be appreciated.

Thanks,
 
Here is what I have, but my app is printing from an asp.net app to a printer
installed on my web server.

I my page load, I have...
for (int i = 0; i <= PrinterSettings.InstalledPrinters.Count - 1; i++)

{

PrinterDropDownList.Items.Add(PrinterSettings.InstalledPrinters);

}

This will add all your installed printers into a drop down list. You need
System.Drawing.Printing in your using list.



PrintDocument doc = new PrintDocument();

// set the printer name

doc.PrinterSettings.PrinterName = printerName;

// add print page event handler

doc.PrintPage += new PrintPageEventHandler(this.PagePrint);

Col3TextForGraphic = Col3Text;

Col4TextForGraphic = Col4Text;

// print the page

doc.Print();



Now, I don't have all the details to hand without ripping my code apart, my
Col3* and Col4* lines are to set up my page. You can ignore those. However,
there should be enough here to help you get going. I can't remember all the
details around the printer handling.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Thanks for the reply. But this does not help me print ANY type of file (eg:
Word doc) to a given printer.

--


David said:
Here is what I have, but my app is printing from an asp.net app to a
printer installed on my web server.

I my page load, I have...
for (int i = 0; i <= PrinterSettings.InstalledPrinters.Count - 1; i++)

{

PrinterDropDownList.Items.Add(PrinterSettings.InstalledPrinters);

}

This will add all your installed printers into a drop down list. You need
System.Drawing.Printing in your using list.



PrintDocument doc = new PrintDocument();

// set the printer name

doc.PrinterSettings.PrinterName = printerName;

// add print page event handler

doc.PrintPage += new PrintPageEventHandler(this.PagePrint);

Col3TextForGraphic = Col3Text;

Col4TextForGraphic = Col4Text;

// print the page

doc.Print();



Now, I don't have all the details to hand without ripping my code apart,
my Col3* and Col4* lines are to set up my page. You can ignore those.
However, there should be enough here to help you get going. I can't
remember all the details around the printer handling.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

kaf said:
Hi,

I have a requirement where I have to print any given file to a specific
printer. My application then consumes the output of this printer. I also
need to do this without any user intervention and without any GUI. I have
managed to get the printing done using Shell Execute, however, it always
shows the associated application even though I have specified
ProcessWindowStyle.Hidden as window style. My code snippets are given
below:

<CODE>
Process objProcess = new Process();

objProcess.StartInfo.FileName = fileName; //file to print

objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden |
ProcessWindowStyle.Minimized;

objProcess.StartInfo.UseShellExecute = true;

objProcess.StartInfo.CreateNoWindow = false;

objProcess.StartInfo.ErrorDialog = false;

objProcess.StartInfo.Verb = "print";



objProcess.Start();

</CODE>

I have searched all over but no solutions so far. I also think that this
should be possible as Microsoft Fax service does exactly this using it's
fax printer.

Any pointers will be appreciated.

Thanks,
 
Ah, sorry. I did not realise that was what you was trying to do. (didnt
read the original message properly)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


kaf said:
Thanks for the reply. But this does not help me print ANY type of file
(eg: Word doc) to a given printer.

--


David said:
Here is what I have, but my app is printing from an asp.net app to a
printer installed on my web server.

I my page load, I have...
for (int i = 0; i <= PrinterSettings.InstalledPrinters.Count - 1; i++)

{

PrinterDropDownList.Items.Add(PrinterSettings.InstalledPrinters);

}

This will add all your installed printers into a drop down list. You need
System.Drawing.Printing in your using list.



PrintDocument doc = new PrintDocument();

// set the printer name

doc.PrinterSettings.PrinterName = printerName;

// add print page event handler

doc.PrintPage += new PrintPageEventHandler(this.PagePrint);

Col3TextForGraphic = Col3Text;

Col4TextForGraphic = Col4Text;

// print the page

doc.Print();



Now, I don't have all the details to hand without ripping my code apart,
my Col3* and Col4* lines are to set up my page. You can ignore those.
However, there should be enough here to help you get going. I can't
remember all the details around the printer handling.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

kaf said:
Hi,

I have a requirement where I have to print any given file to a specific
printer. My application then consumes the output of this printer. I also
need to do this without any user intervention and without any GUI. I
have managed to get the printing done using Shell Execute, however, it
always shows the associated application even though I have specified
ProcessWindowStyle.Hidden as window style. My code snippets are given
below:

<CODE>
Process objProcess = new Process();

objProcess.StartInfo.FileName = fileName; //file to print

objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden |
ProcessWindowStyle.Minimized;

objProcess.StartInfo.UseShellExecute = true;

objProcess.StartInfo.CreateNoWindow = false;

objProcess.StartInfo.ErrorDialog = false;

objProcess.StartInfo.Verb = "print";



objProcess.Start();

</CODE>

I have searched all over but no solutions so far. I also think that this
should be possible as Microsoft Fax service does exactly this using it's
fax printer.

Any pointers will be appreciated.

Thanks,

 
kaf said:
Thanks for the reply. But this does not help me print ANY type of file (eg:
Word doc) to a given printer.

I don't recall whether there's a DDE command to print without showing a
UI. You might look into that. Alternatively, if you can use OLE to
embed a file from another application in your own document, then
printing your own document will effectively print that file.

Either way, AFAIK there's no managed support for these operations.
You'll need to use the unmanaged Win32 API via p/invoke to get what you
want, assuming it can be done at all. Note that even using DDE or OLE,
the document will have to be supported by an application that does in
fact support the DDE or OLE operations you want. There's not a
general-purpose, OS-supported way to print arbitrary documents, never
mind without showing a particular application's UI.

Pete
 
kaf said:
Thanks for the reply. But this does not help me print ANY type of file (eg:
Word doc) to a given printer.

That's impossible. Other than the Office suites, there are not all that
many applications that implement the "print" verb.
 
That's impossible. Other than the Office suites, there are not all that
many applications that implement the "print" verb.

I have come to the same conclusion. But somehow Microsoft Fax service does
exactly this. It can print ANY registered file type to a fax printer and get
the fax file generated. I don't know how it does it without showing the
corresponding application, but I intend to do the same.
 
Hello,

Maybe a stupid suggestion but can't you position the writing applications
window outside of the screen?

// Anders
--

kaf said:
That's impossible. Other than the Office suites, there are not all that
many applications that implement the "print" verb.

I have come to the same conclusion. But somehow Microsoft Fax service does
exactly this. It can print ANY registered file type to a fax printer and
get the fax file generated. I don't know how it does it without showing
the corresponding application, but I intend to do the same.
 
Maybe a stupid suggestion but can't you position the writing applications
window outside of the screen?

It's difficult because ShellExecute gives me very few options. I may have to
search for a window handle by which time, the application has already shown
the window.

I am even thinking of launching those applications on a separate desktop.
But earlier this looked like too complicated a solution for this problem. I
also could not figure out how to ask ShellExecute to launch the application
(or execute the verb) on a different desktop created by me.

--




Anders Eriksson said:
Hello,

Maybe a stupid suggestion but can't you position the writing applications
window outside of the screen?

// Anders
--
 
Back
Top