Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
printing blank page in printer as well as microsoft xps document also.i changed in below my code.But I am getting blank only.


What I have tried:

printing blank page in printer as well as microsoft xps document also

     private void printButton_Click(object sender, EventArgs e)
    {
        CaptureScreen();

        printDialog1.AllowSomePages = true;

        printDialog1.ShowHelp = true;

        printDialog1.Document = printDoc1;

        DialogResult result = printDialog1.ShowDialog();

        if (result == DialogResult.OK)
        {
            printDoc1.Print();
        }
    }        

    private void CaptureScreen()
    {
        Graphics myGraphics = this.CreateGraphics();
        Size s = this.Size;
        memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
        Graphics memoryGraphics = Graphics.FromImage(memoryImage);
        memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
    }

    void printDoc1_PrintPage(object sender, PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(memoryImage, 0, 0);
    }
Posted
Updated 29-Mar-18 21:09pm

1 solution

Start by checking what you are producing: add these two lines:
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
memoryImage.Save(@"D:\Temp\Created.jpg", ImageFormat.Jpeg);  // ADD THIS
And
e.Graphics.DrawImage(memoryImage, 0, 0);
memoryImage.Save(@"D:\Temp\Printed.jpg", ImageFormat.Jpeg);
Then look at the two images using Windows Explorer. Are they the same? Are they a picture of your object? What size are they? Or are they blank? Are they both even there?

If they are good, then you can start looking at what might be causing the "blank page" - but start be ensuring that what you are drawing is "real".
 
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