我想獲得新的生產線,但如果我用\ n它不添加東西串像\ r \ n(不工作)PDFsharp換行符
gfx.DrawString("Project No \n" + textBoxProjNumber.Text, fontUnder, XBrushes.Black, 230, 95);
幫助任何方式有新線
不起作用。
我想獲得新的生產線,但如果我用\ n它不添加東西串像\ r \ n(不工作)PDFsharp換行符
gfx.DrawString("Project No \n" + textBoxProjNumber.Text, fontUnder, XBrushes.Black, 230, 95);
幫助任何方式有新線
不起作用。
您是否嘗試過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);
爲什麼我們需要矩形? – 2011-03-16 07:57:31
這是有效的。謝謝。還有一件事是,在migradoc中如何檢測段落是否長於頁面並自動插入分頁符 – 2011-03-16 08:00:08
我剛纔找到的一些東西(我知道pdfsharp已被更好的庫取代),但在VB.net中,你必須使用+ vbNewLine而不是/ n – ShiftyThomas 2013-06-12 09:49:24
這是我做過什麼,使用矩形類不包括:
我有一個定義的右側限制和確定當前字符串是否會大於設定範圍。如果是的話,我寫了。否則,我繼續增加它。
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
我知道我遲到了這個問題,但我希望它可以幫助別人。
類似'XTextFormatter'類的方法,但不太靈活。 – 2017-06-29 17:24:52
如果它是一種控制檯模式,那麼調用DrawString()兩次? – BlackBear 2011-03-15 22:29:17
對不起,沒有? – 2011-03-15 22:50:52
嘗試調用DrawString()爲每一行你想打印,例如DrawString(Project No「); DrawString(textBoxProj .....); – BlackBear 2011-03-15 22:54:13