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 \\n
escape c
For me it worked like this:
document.Add(new Chunk("\n"));
worked fine, but the space was greater than I expected. so I went with this:
document.Add(new Paragraph(" "));
the result was a fine and regular space between my components.
document.Add(new Paragraph(" "));
works well for me. Remember, the Paragraph
statement automatically adds a line feed. All you have to do is give it something to render. In this case, a space will do just fine.
I know this is a little old, but there is yet another way. Here is a little from one report I used.
var contents = new Paragraph();
contents.Alignment = Element.ALIGN_CENTER;
contents.Add(new Chunk(string.Format("{0} {1}\n", emp.FirstName, emp.LastName), new Font(baseFont, 11f, Font.BOLD)));
contents.Add(new Chunk(string.Format("Dept: {0}\n", emp.Departments.Title), new Font(baseFont, 9f)));
contents.Add(new Chunk(string.Format("Wk Ending: {0}\n", _date), new Font(baseFont, 9f)));
As you can see, what i did was create chunks. This allows you use to use "\n" to preform line breaks.
I am just trying this tool and for adding new line I just added '\r\n' and it did work. Like this below.
String content01 = "Nulla condimentum dui lobortis risus viverra, eu pellentesque sem blandit.\r\nUt congue turpis quis sapien mollis, vitae rutrum mi consectetur. Integer maximus nisl sed tellus pharetra pharetra.";
Phrase contentPhrase = new Phrase(content01);
Paragraph contentPr = new Paragraph();
contentPr.Add(contentPhrase);
Then added the Paragraph contentPtr to my Document instance.