Click here to Skip to main content
15,798,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to print a document with specified size say width 18.5cm and height 16.5cm. and one more question how can i print multiple document.

my code is given below
class PrintClass:BasicClass
public void print()

    PrintDialog pd = new PrintDialog();
    PrintDocument pdoc = new PrintDocument();
    PrinterSettings ps = new PrinterSettings();
    PaperSize psize = new PaperSize();
    pdoc.DefaultPageSettings.Landscape = true;
    pd.Document = pdoc;
    pd.Document.DefaultPageSettings.PaperSize = psize;
    pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);

    DialogResult result = pd.ShowDialog();
    if (result == DialogResult.OK)
        PrintPreviewDialog ppd = new PrintPreviewDialog();
        ppd.Document = pdoc;
        ppd.PrintPreviewControl.Zoom = 1.5;
        ((Form)ppd).WindowState = FormWindowState.Maximized;
        DialogResult ppdResult = ppd.ShowDialog();

void pdoc_PrintPage(object sender, PrintPageEventArgs e)
    Graphics g = e.Graphics;
    //string str1 = "XYZ";
    //Font fnt1 = new Font("Arial", 12.5f);            
    g.DrawString(str, fnt, new SolidBrush(Color.Black), 10, 10);


1 solution

Well, you could start by using the overloaded constructor that takes a paper size: PaperSize Constructor (String, Int32, Int32)[^] instead of the default constructor.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900