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

Jay-R Hayashi 206 Reputation points
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.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,521 questions
C#
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.
10,205 questions
C++
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.
3,519 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
935 questions
Windows Server Printing
Windows Server Printing
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Printing: Printer centralized deployment and management, scan and fax resources management, and document services
640 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 24,281 Reputation points Microsoft Vendor
    2023-01-09T08:50:53.383+00:00

    @Jay-R Hayashi , 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