Home All Groups Group Topic Archive Search About

Print from console application

Author
30 May 2010 12:04 PM
Frank GTL
Hi
I am trying to make my program send a page to a printer from my console
application.
I want to print the content of a string variable.

I have tried the following to print from a text file:

Dim myPrint as New PrintDocument
myPrint.DocumentName="C:\temp\MyTextDocument.txt"
myPrint.Print

This works, but the printed page is blank.

However - what I really need is to print a text string (several lines).

Any ideas?


best regards
Frank

Author
30 May 2010 12:19 PM
Family Tree Mike
On 5/30/2010 8:04 AM, Frank GTL wrote:
Show quoteHide quote
> Hi
> I am trying to make my program send a page to a printer from my console
> application.
> I want to print the content of a string variable.
>
> I have tried the following to print from a text file:
>
> Dim myPrint as New PrintDocument
> myPrint.DocumentName="C:\temp\MyTextDocument.txt"
> myPrint.Print
>
> This works, but the printed page is blank.
>
> However - what I really need is to print a text string (several lines).
>
> Any ideas?
>
>
> best regards
> Frank
>
>

Printing works the same in .Net, whether it is from a console app or
from a windows forms app.  Try the example at
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx.
  It's a bit more involved than you have shown.

--
Mike
Author
30 May 2010 4:59 PM
Herfried K. Wagner [MVP]
Am 30.05.2010 14:04, schrieb Frank GTL:
> I am trying to make my program send a page to a printer from my console
> application.
> I want to print the content of a string variable.
>
> I have tried the following to print from a text file:
>
> Dim myPrint as New PrintDocument
> myPrint.DocumentName="C:\temp\MyTextDocument.txt"
> myPrint.Print
>
> This works, but the printed page is blank.
>
> However - what I really need is to print a text string (several lines).

Handle the 'PrintDocument' object's 'PrintPage' event and send the text
to the printer there using 'e.Graphics.DrawString(...)'.

--
  M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>