Click here to Skip to main content
12,884,509 members (33,664 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 15 Jun 2007

Multi Page Multi Column Text Printing

, 15 Jun 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
How to do a multi page multi column text printing
Screenshot - PrintApp.jpg

Screenshot - PrintPreview.jpg


Problem – there are many examples of how to print multi page text to the printer. Unfortunately none that I found worked for me. I need to print a two column multi page custom report, when I do not know ahead what I will be printing. Good news – I do not have to deal with the case when width of the printed object is larger than page width.

I am not very happy with the solution I found and will greatly appreciate anyone pointing out a better solution for me. On the other hand, if anyone has to deal with a similar problem, this works.

Using the Code

I created two arrays of strings with random font size and attributes.

The Reset button resets those two columns so that a lot of random testing can be done.

The general idea behind the logic is that the code keeps track of the number of pages. The current page height is the visible area of the printer page minus 2 vertical margins. The vertical offset is (number of pages) * (visible area).

The complexity starts when you have a string that is 'nishta hin nishta her' – split in the middle between two pages. I added the offset that will move everything "down".

The main logic is in the DrawString method:

private void DrawString(Graphics g, string s, Font font, Brush brush, float x, float y)
    y += m_fVerticalMargin + m_fPrevPageSmallTopOffset - m_fTopOffset;
    if (y < m_fVerticalMargin) // Below the printable area

    if (y > m_fPageHeight + m_fVerticalMargin) // Above the printable area
        if (!m_bMorePages) // It is possible that there is no split
            m_bMorePages = true;

    SizeF pSize = g.MeasureString(s, font);
    if (y + pSize.Height > m_fPageHeight + m_fVerticalMargin) 
    // This text is split between two pages - everything needs to be moved down;
        m_fThisPageSmallTopOffset = Math.Max(
            m_fPageHeight + m_fVerticalMargin - y);
        m_bMorePages = true;

    g.DrawString(s, font, Brushes.Black, x, y);


  • 15th June, 2007: Initial post


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


About the Author

Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170422.1 | Last Updated 15 Jun 2007
Article Copyright 2007 by Fiwel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid