Adding a New Line in iTextSharp

后端 未结 10 1653
伪装坚强ぢ
伪装坚强ぢ 2021-02-19 00:36

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

相关标签:
10条回答
  • 2021-02-19 01:21

    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.

    0 讨论(0)
  • 2021-02-19 01:26

    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.

    0 讨论(0)
  • 2021-02-19 01:26

    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.

    0 讨论(0)
  • 2021-02-19 01:29

    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.

    0 讨论(0)
提交回复
热议问题