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,