We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

First Line indent in TextFragment


I want to insert a large of text into pdf. But i can`t do first line indent after new line feed.

I do this:
var page = pdfDoc.Pages[1];

        var textFragment = new TextFragment(largeText); //large text is string with text on several pages

        textFragment.TextState.HorizontalAlignment = HorizontalAlignment.Justify;
        textFragment.TextState.Font = FontRepository.FindFont("Consolas");
        textFragment.TextState.FontSize = 12;
        textFragment.Margin = new MarginInfo(20, 3, 1, 3);
        textFragment.TextState.LineSpacing = 4;


I try to insert some whitespaces before Environment.NewLine in variable largeText. But when i set HorizontalAlignment to Justify there have a different width.
I have tried use negative value of SubsequentLineIndent, but first characters in subsequent lines didn`t fit in TextFragment Rectangle.
Can you help me?


Thanks for contacting support.

Could you please share the output PDF document which you have generated at your side. Also, please share the screenshot of the issue which you are observing in the output PDF. We will test the scenario in our environment and address it accordingly.

result.pdf (108.4 KB)
2.jpg (225.3 KB)
1.jpg (795.1 KB)

On 1.jpg issue.
On 2.jpg once more trouble. I set Left Margin 20px (in code of first message)
textFragment.Margin = new MarginInfo(20, 3, 1, 3);
On first page margin is 20px, on second and third margin 0px. I don`t really need this margin, but it seems like api bug.


Thanks for sharing requested information.

We have tested the scenario in our environment and were able to replicate both issues. Please note that there was a property i.e. Text.FirstLineIndent in old generator approach which served the purpose of adding left hanging paragraphs. I am afraid the property is not currently present in new Aspose.Pdf generator.

Nevertheless, we have logged a feature request as PDFNET-45962 in our issue tracking system to implement the property to add indent for first line in a paragraph.

We have also logged this issue as PDFNET-45963 in our issue tracking system. We will definitely look into details of both logged tickets and keep you posted with the status of their resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.

And no way to do it? Only form docx and convert to pdf?

I try use html, because html can do first line indent, but…
In first comment example add at first:
largeText = "<p style =\"text - indent: 1.5em\">" + largeText + "</p>";
and then replace TextFragment to HtmlFragment
after this, when i try to “.ProcessParagraphs()” or Save pdf to Stream, occured a OutOfMemoryException. (process consumed 4gb memory and crashes).


Thanks for sharing further details.

Would you kindly share the complete text i.e. largeText in a .txt file. We will test the scenario with your text and address it accordingly.

The issues you have found earlier (filed as PDFNET-45962) have been fixed in Aspose.PDF for .NET 19.3.