Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print a word document using the printDocument object 1

Status
Not open for further replies.

vatawna

Programmer
Feb 24, 2004
67
US
In my windows form, I have the following method to print out word documents when the printDocument1.Print() statement is called:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float yPos = 0;
float lines = e.MarginBounds.Height / font.GetHeight(e.Graphics);

int count = 0;
string line = null;
while ((count < lines) && ((line = reader.ReadLine()) != null))
{
yPos = topMargin + (count * font.GetHeight(e.Graphics));
e.Graphics.DrawString(line, font, Brushes.Black, leftMargin, yPos, new StringFormat());
count++;
}

if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
}


The problem is the printed document shows something like the following besides the content of the file:


[][][][][][][][][][][][][][][]>[][][][][][][][][][][][][]*
[][][][][]F[][][][][]b[][][][][][][][][][]0[][]F[][]q[][][]


etc., where the [] shows in the printed document as squares. The word macros that I wrote and other data such as HelpContextID that I don't know where they came from also show in the printed document.

Does anyone know know to fix this?

Thanks.
 
To print a Word document you need to instantiate a copy of MS-Word and tell it to print it.

Or.. there are some 3rd party libraries that you can buy that know how to read a .doc file and print them.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top