Printing image and if image is exceed if 1st page proceed to 2nd page using printDocuments c#

Anonymous
2023-01-06T15:27:34.75+00:00

Attention all programmer,

I hope you can help me to solve my problem.

My problem is show in picture.

This is my 1st problem, the image has exceeded for 8 rows. But this problem has been fixed now.
Note: "Never mind the text write in this image. Sorry it's my mistake"

276972-untitled.png

Now as you can see the picture below have a message, this problem has been fixed.

276934-untitled2.png

Now this is my problem! please read the text written in the picture, sorry to my grammar not good. By the way I am using
printDocument in c#.
276973-untitled3.png
I pray someone can help me to fix this problem.

Developer technologies | Visual Studio | Debugging
Windows for business | Windows Server | User experience | Print jobs
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Microsoft Security | Microsoft Graph
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack J Jun 25,316 Reputation points
    2023-01-09T08:50:53.383+00:00

    @Anonymous , Based on my further test, I managed to solve the problem. When we set e.HasMorePages = true; every time, it will generate a new page.

    Please refer to the following code.

     int m_CurrentPage = 0;  
            private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)  
            {  
                int offsety = 55;  
                int fontheight = 200;  
                for (int i = m_CurrentPage; i < dataGridView1.Rows.Count - 1; i++)  
                {  
                    if (offsety > e.MarginBounds.Height)  
                    {  
                        e.HasMorePages = true;  
                        offsety = 55;  
                        return;  
      
                    }  
                    byte[] arr = (byte[])dataGridView1.Rows[i].Cells[0].Value;  
                    var image = byteArrayToImage(arr);  
                    e.Graphics.DrawImage(image, 620, offsety, 120, 120);  
                    offsety += fontheight;  
                    m_CurrentPage++;  
      
                }  
                e.HasMorePages = false;  
      
      
            }  
    

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.