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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change printDocument paper size

Status
Not open for further replies.

Axien

Programmer
Aug 10, 2002
7
LT
Hi all,
I want to change paper size to A4, but I don't know how to do it.
I tried to do in this way:

printDocument.DefaultPageSettings.PaperSize.PaperName
= "PaperA4";

but got an exception "Can't change a PaperSize unless its Kind is Custom", then I tried to change that PaperKind:

System.Drawing.Printing.PaperKind kind =
System.Drawing.Printing.PaperKind.A4;
// some Code here //
printDocument.DefaultPageSettings.PaperSize.Kind = kind;

but that "..PaperSize.Kind" is read only.
Maybe someone has some IDEAS ???
 
Hello Axien,
Try the following

printDocument.DefaultPageSettings.PaperSize= new System.Drawing.Printing.PaperSize("PaperA4",840,1180);


This should set the size of the paper to A4. The next two parameters (after the "PaperA") are the Width and Height of the paper on 100th of inch so if my calculations are correct (see why i said should :) ) it will set the size of the paper to A4. Unfortuantely my printer is not working (outof ink) so when you test it please let me know.

Hope that this helps,
Camel
 
Thanks Camel,
it realy works :), but paper A4 Width = 826, Heigth = 1169. I just checked it with pageSetupDialog object:

pageSetupDialog.ShowDialog();
// then I set paper format to A4 //
txtWidth.Text = pageSetupDialog1.Document.DefaultPageSettings.PaperSize.Width.ToString();
txtHeight.Text = pageSetupDialog1.Document.DefaultPageSettings.PaperSize.Height.ToString();

// there txtWidth and txtHeight are TextBox class objects
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top