将具有多行的String添加到PdfAcroField多行中

时间:2015-01-10 17:09:41

标签: c# pdfsharp

我在PDF文档中将字符串添加到PdfActoField中,如下所示:

PdfSharp.Pdf.AcroForms.PdfAcroField fieldLocation = fields["location"];
PdfSharp.Pdf.AcroForms.PdfTextField txtFieldLocation;
if ((txtFieldLocation = fieldLocation as PdfSharp.Pdf.AcroForms.PdfTextField) != null)
                {
                    txtFieldLocation.ForeColor = System.Drawing.Color.Black;
                    txtFieldLocation.MultiLine = true;

                    var sb = new System.Text.StringBuilder();
                    sb.Append("John Doe");
                    sb.Append(Environment.NewLine);
                    sb.Append("Text from new line1");
                    sb.Append(Environment.NewLine);
                    sb.Append("Text from new line2");
                    sb.Append(Environment.NewLine);
                    sb.Append("Text from new line3");
                    txtFieldLocation.Text = sb.ToString();
                }

我的字符串已添加到一行中。 此外,我尝试使用“\ r \ n”添加多行的字符串,但仍然没有成功 一些建议如何添加多行字符串?

1 个答案:

答案 0 :(得分:-3)

您应该使用AppendLine代替Append