Automatically Word-Wrapping Text To A Print Page?

Posted by sooprise on Stack Overflow See other posts from Stack Overflow or by sooprise
Published on 2011-02-16T15:10:17Z Indexed on 2011/02/16 15:25 UTC
Read the original article Hit count: 233

Filed under:
|
|

I have some code that prints a string, but if the string is say: "Blah blah blah"... and there are no line breaks, the text occupies a single line. I would like to be able to shape the string so it word wraps to the dimensions of the paper.

private void PrintIt(){
    PrintDocument document = new PrintDocument();
    document.PrintPage += (sender, e) => Document_PrintText(e, inputString);
    document.Print();
}

static private void Document_PrintText(PrintPageEventArgs e, string inputString) {
    e.Graphics.DrawString(inputString, new Font("Courier New", 12), Brushes.Black, 0, 0);
}

I suppose I could figure out the length of a character, and wrap the text manually, but if there is a built in way to do this, I'd rather do that. Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about printing