0

I want to print a Multiline Text.
I searched and I found that I can print it with TextRenderer, but the text is printed very small in the left top of the paper. I don´t know why.

Code:

PrintDocument pd = new PrintDocument();
pd.PrintPage += PrintPage_Header;
pd.PrintPage += PrintPage_Adresse;

// pd.Print();

printPrvDlg.Document = pd;
printPrvDlg.ShowDialog();

private void PrintPage_Adresse(object sender, PrintPageEventArgs e)
{
    printFont = new Font("Arial", 10, FontStyle.Bold);
    Size size = TextRenderer.MeasureText(e.Graphics, stringToPrint, this.printFont, proposedSize, TextFormatFlags.WordBreak);
    xPos = new System.Drawing.Rectangle(new Point(22, 150), size);
    TextRenderer.DrawText(e.Graphics, stringToPrint, this.printFont, xPos, Color.Black, Color.White, TextFormatFlags.WordBreak);
}

I can´t find the problem.

Jimi
  • 29,621
  • 8
  • 43
  • 61
tom
  • 1
  • 1
  • 1
    This is an english only site. Please translate your question to english – Sir Rufo Mar 21 '20 at 07:23
  • Where is the `e.Graphics` object coming from? What Graphic unit is it set to? What is the Font size? What is the Font `emSize` and `GraphicsUnit` set to? Where are you drawing? Why is the queston's title in german? To make it more challenging :)? – Jimi Mar 21 '20 at 07:41
  • You should edit your question to update it with new details. Anyway, you cannot use TextRenderer to draw text on a `PrintDocument` graphics. You have to use the `e.Graphics` object to measure and draw the text. You didn't specify the Graphics Units in use. – Jimi Mar 21 '20 at 07:57
  • and how can I make a wordbreak with Drawstring ? – tom Mar 21 '20 at 08:02
  • WordBreak breaks text at the end of a word. It's the default behavior of `Graphics.DrawString()` (you have to specify `StringFormatFlags.NoWrap` to make it work differently). You can use `StringFormat.GenericTypographic` for a generic pre-set that works well with `PrintPage`. You didn't specify the Graphic Units in use. – Jimi Mar 21 '20 at 08:10
  • 1
    Btw, always specify the bounding rectangle of a section of text and consider the hard and soft margins of the physical page (if this goes to a hard Printer or PDF Printer). – Jimi Mar 21 '20 at 08:20

0 Answers0