AppendParagraph Error when TextParagraph with TextState object

I was looking for wordwrap function with TextState property and I found this is most suitable example for me.


            Document doc = new Document(inFile);
        Page page = (Page)doc.Pages[1];
        
        <span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">// create text paragraph

TextParagraph paragraph = new TextParagraph();

        <span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">// set the paragraph rectangle

paragraph.Rectangle = new Rectangle(100, 600, 200, 700);

        <span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">// set word wrapping options

paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;

        <span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">// append string lines

paragraph.AppendLine(“the quick brown fox jumps over the lazy dog”);
paragraph.AppendLine(“line2”);
paragraph.AppendLine(“line3”);

        <span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">// append the paragraph to the Pdf page with the TextBuilder

TextBuilder textBuilder = new TextBuilder(page);
textBuilder.AppendParagraph(paragraph);

        <span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">// save Pdf document

doc.Save(outFile);




Above code works fine, but when I add ‘TextState’ to paragraph variable as second parameter it gives me an error.




The following is my code:

Document doc = new Document(“C:\test\52923209.pdf”);
Page page = (Page)doc.Pages[1];
// create text paragraph
TextParagraph paragraph = new TextParagraph();
// set the paragraph rectangle
paragraph.Rectangle = new Aspose.Pdf.Rectangle(30, 600, 570, 700);
// set word wrapping options
paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
paragraph.AppendLine(“the quick brown fox jumps over the lazy dog the quick brown” +
" fox jumps ov the lazy dog the quick brown fox jumps ov the lazy dog the quick" +
“brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog”,new TextState(22));
// append the paragraph to the Pdf page with the TextBuilder
TextBuilder textBuilder = new TextBuilder(page);
textBuilder.AppendParagraph(paragraph);

// save Pdf document
Random random = new Random();
doc.Save(“c:\test\” + random.Next(10000000, 99999999).ToString() + “.pdf”);


== ERROR Detail: ==================================
The exception occurs on this line
- textBuilder.AppendParagraph(paragraph);
and The error is
- “Object reference not set to an instance of an object.”
===============================================



Please investigate this.

Thanks,

Hi,


Thanks for using our products. I am testing this scenario and will get back to you soon. We are sorry for this delay and inconvenience.

Hi Yang Kyu,


Thanks for your patience and sorry for the delayed response.

I have tested the scenario using current latest release version of Aspose.Pdf for .NET 7.7.0 and I am unable to notice any issue. The resultant PDF is properly being generated and also the text appearing in resultant file has font size of 22. Can you please try using the latest release version and in case you still face any issue or you have any further query, please feel free to contact. We are really sorry for this delay and inconvenience.