How do I print someting in landscape orientation in C#?

The following is the relevant code snippet from a simple C# program I am writing.  All it does it prompt the user for a file name, then a printer, and dumps a text file to it.

What I need to do is make the default orientation landscape regardless of what the driver is set to default to.  The user can click portrait if they want, but I want the landscape radio button on the print dialog to be ticked automatically.

Any suggestions?
private void printButton_Click(object sender, System.EventArgs e)
		{
			// Allow the user to select a file.
			OpenFileDialog ofd = new OpenFileDialog();
			if( DialogResult.OK == ofd.ShowDialog(this) )
			{
				// Allow the user to select a printer.
				PrintDialog pd  = new PrintDialog();
				pd.PrinterSettings = new PrinterSettings();
				if( DialogResult.OK == pd.ShowDialog(this) )
				{
					string printPath = ofd.FileName;
					fileToPrint = new System.IO.StreamReader(printPath);
					printFont = new System.Drawing.Font("Courier", 12);
					printDocument1.Print();
					fileToPrint.Close();
				}
			}
		}
 
		private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
		{
			float yPos = 0f;
			int count = 0;
			float leftMargin = e.MarginBounds.Left;
			float topMargin = e.MarginBounds.Top;
			string line = null;
			float linesPerPage = e.MarginBounds.Height/printFont.GetHeight(e.Graphics);
			while (count < linesPerPage)
			{
				line = fileToPrint.ReadLine();
				if (line == null)
				{
					break;
				}
				yPos = topMargin + count * printFont.GetHeight(e.Graphics);
				e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
				count++;
			}
			if (line != null)
			{
				e.HasMorePages = true;
			}
		}
 
		private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
		{
		
		}
	}
}

Open in new window

LVL 14
cuziyqAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JimBrandleyCommented:
This should do it:
pd.DefaultPageSettings.Landscape = true;

Jim
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.