Skip to content

Print image from picturebox wchich feet in A4 size paper

sarika sarikaa

Asked May 5, 2018, 12:56 AM EDT1 answer
Share
LinkedInX
i  want to print image in A4 size paper from picturebox on click on print button.
 
 
 
i have tried this , but when i will print this image on A4 size paper it cant print the hole image.
 
C#
private void button1_Click(object sender, EventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            PrintDocument doc = new PrintDocument();
            doc.PrintPage += Doc_PrintPage;
            pd.Document = doc;
            if (pd.ShowDialog() == DialogResult.OK)
                doc.Print();

        }

        private void Doc_PrintPage(object sender, PrintPageEventArgs e)
        {


            Bitmap bm = new Bitmap(pictureBox1.Width,pictureBox1.Height);
            pictureBox1.DrawToBitmap(bm, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
            e.Graphics.DrawImage(bm,0,0);
            bm.Dispose();

        }
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Željko Perić
    +1
    Hello,
    Check the size of picture box and size of image.
    Size of picture box should be smaller than A4 paper size.
     
    If Size of image is larger than size of picture box,
    size mode property of picture box should be set to zoom or strech image, 
    not to normal, center image or auto size image.
     
    Also check the paper size and orientation at printer settings dialog before printing image.
     
     I have set picture box size to 800 x 600 pixels, and size mode property to strech image,
    and program works fine.
     
    All the best,
    Željko Peric
    +1