Подтвердить что ты не робот

Разрыв строки PDFsharp

Я пытаюсь получить новую строку, но если я использую \n, он не работает.

Любой способ получить новую строку, добавив что-то в строку, например \r\n (что также не работает)

gfx.DrawString("Project No \n" + textBoxProjNumber.Text, fontUnder, XBrushes.Black, 230, 95);

(фрагмент примера показывает, что я пробовал, но не работает).

4b9b3361

Ответ 1

Вы пробовали класс XTextFormatter?

Смотрите здесь: http://www.pdfsharp.net/wiki/TextLayout-sample.ashx

Фрагмент кода:

PdfDocument document = new PdfDocument();

PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold);
XTextFormatter tf = new XTextFormatter(gfx);

XRect rect = new XRect(40, 100, 250, 220);
gfx.DrawRectangle(XBrushes.SeaShell, rect);
tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

Ответ 2

Это то, что я сделал, что не связано с использованием класса Rect:

Я имел определенный правый боковой предел и определял, будет ли текущая строка больше, чем установленные границы. Если бы это было так, я написал это. В противном случае я продолжал добавлять к нему.

foreach (string field in temp)
{
    if (field == string.Empty)
    {
        continue;
    }
    else
    {
        tempSB.Clear();
        tempSB.Append(sb.ToString());
        tempSB.Append(field).Append(", ");  //append the incoming value to SB for size testing

        if (gfx.MeasureString(tempSB.ToString(), defaultFont).Width > 500)  //if the incoming string is bigger than the right bounds, write it and clear SB
        {
            gfx.DrawString(sb.ToString(), defaultFont, blackBrush, 50, currentLine + defaultSpacing);
            currentLine += 15;
            sb.Clear();
            sb.Append(" " + field).Append(",");  //add the overflow to the beginning of the next line
         }
         else
         {
             sb.Append(field).Append(", ");  //if it is not too big, append it
         }
     }

 }
 if (sb.Length > 0 && sb[sb.Length - 1] == ',') sb.Length--;
 gfx.DrawString(sb.ToString(), defaultFont, blackBrush, 50, currentLine + defaultSpacing); //write out whatever has not already been written out

Я знаю, что опаздываю на этот вопрос, но надеюсь, что это может помочь кому-то.