在 PDFsharp 中一定数量的字符后,如何使字符串跳转到新行?

How can I make a string jump to a new line after a certain number of characters in PDFsharp?

我正在尝试放置一个从我的数据库中检索到的字符串,因此很难拆分该字符串。

            XRect rect = new XRect(page8margin, page8margin + 60 + (3 * page8margin), 300, 300);
            gfx8.DrawRectangle(XBrushes.LightGray, rect);

            tf.DrawString(interview.Job.Summary, smallerFont, XBrushes.Black, rect, XStringFormats.TopLeft);

但似乎字符串只是忽略了边框而只写在一行中。如何拆分字符串并使其在一定数量的字符后跳转到新行?

class XTextFormatter(您可能正在使用,根据变量名 tf 判断 - 感谢您显示这么多代码)在空白字符处换行。

包含 XTextFormatter 的源代码,因此您可以根据需要对其进行调整。

屏幕截图上显示的文本有一个很长的单词,XTextFormatter 的默认实现不会打断单词,无论它们有多长。

打破长单词是一项特殊要求,但您可以为此调整 XTextFormatter class。或者使用 XTextFormatter class 作为灵感来编写自己的代码。

也许您只需要用 "Lorem ipsum ..." 段进行测试即可解决问题。