Search code examples
c#itext7

itext7 Overwriting long string value


I have the following code:

    void Main()
   {
       var writer = new PdfWriter(@"c:\temp\Overwrite.pdf");
            var pdf = new PdfDocument(writer);
            var document = new Document(pdf);
    
        var p = new Paragraph($"Feature: 4.2 - Release Selection and a very big welcome to the Community this has been a very good project indeed, I sure do like it. How about yourself, very big welcome to the Community, this has been a very good project indeed, I do like it. Selection and a very big welcome to the Community this has been a very good project indeed, I sure do like it. ").SetKeepWithNext(true)
                    .SetMarginTop(10)
                    .SetMarginBottom(10)
                    .SetFixedLeading(0f);
    
        document.Add(p);
        
        document.Close();
    }

But the output ends up like the following: enter image description here How can i have the text wrap to the next line without overwriting itself ?


Solution

  • Im not sure what this line is doing, but its causing the issue, if you comment it like i did here, your text works.

    var p =
            new Paragraph(s)
            .SetKeepWithNext(true)
            .SetMarginTop(10)
            .SetMarginBottom(10);
            //SetFixedLeading(0f);