I’ve been trying to solve this problem for a while now to no avail. I have some text in iTextSharp I’m trying to put on a newline. I’ve tried using the
escape character, Environment.NewLine
, and document.Add(new Phrase(Environment.NewLine))
without any success. So is there a way to do this? Here is the piece of my code I’m trying to do it in (note the lines commented with //Doesn t work
):
//Open the reader
PdfReader reader = new PdfReader(oldFile);
Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);
// open the writer
FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
//Configure the content
PdfContentByte cb = writer.DirectContent;
// select the font properties
BaseFont bf = BaseFont.CreateFont("c:\windows\fonts\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.BLACK);
cb.SetFontAndSize(bf, 10);
//Write the text here
cb.BeginText();
text = "F
";//Doesn’t work
document.Add(new Phrase(Environment.NewLine));//Doesn’t work
text += "o
";
text += Environment.NewLine;//Doesn’t work
text += "o
";
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, 85, 311, 0);
cb.EndText();
//Create the new page
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);
//Close all streams
document.Close();
fs.Close();
writer.Close();
reader.Close();
有什么建议吗?
<强>编辑一: 强>
Still not working with document.Add(new Paragraph("
"));
. Did I do it wrong?
cb.BeginText();
text = "F";
document.Add(new Paragraph("
"));
text += "o";
document.Add(new Paragraph("
"));
text += "o";
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, 85, 311, 0);
cb.EndText();