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

Free Support Forum - aspose.com

TextFragment height cuts off text

Hello, I have a fresh install of Aspose PDF 19.4.0. I am trying to add a TextFragment to a TextParagraph and then to a TextBuilder per some examples. Unless I make the font size smaller I can not fit in a large amount of text. Shouldn’t the TextFragment height be automatic? I have tried by adding the text when the TextFragment is created and also tried adding it after the TextState settings I have, still cannot fit a large amount of text unless font size is smaller.

Code below:

var page = document.Pages.Add();
TextBuilder builder = new TextBuilder(page);
// Create text paragraph
TextParagraph paragraph = new TextParagraph();
paragraph.HorizontalAlignment = HorizontalAlignment.Center;
paragraph.VerticalAlignment = VerticalAlignment.Bottom;
// Specify the location to add TextParagraph
paragraph.Rectangle = new Rectangle(18, 8, page.PageInfo.Width - 18, 300);

        // Specify word wraping mode
        paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
        // Create text fragment
        //Width:{paragraph.Rectangle.Width}x{paragraph.Rectangle.Height} {paragraph.Rectangle.LLX}-{paragraph.Rectangle.LLY} x {paragraph.Rectangle.URX}-{paragraph.Rectangle.URY} 
        TextFragment disclaimerFragment = new TextFragment();
        
        disclaimerFragment.TextState.FontSize = 11; //if set to 7 my text fits
        disclaimerFragment.TextState.ForegroundColor = Color.FromRgb(System.Drawing.Color.SlateGray);
        disclaimerFragment.Text = $"{content}"; //content added from variable, large paragraph, 600 characters
        
        // Add fragment to paragraph
        paragraph.AppendLine(disclaimerFragment);

        // Add paragraph
        builder.AppendParagraph(paragraph);

Any help is appreciated, thanks!

@t9creative

Thank you for contacting support.

Please note that you do not necessarily need to specify rectangle coordinates before adding text. Below code snippet can be used to add paragraphs on a page in top to down flow mode where next page will be added if text overflows from first page. In case of adding text at specific location, you may set Position property as explained in Adding Text.

Document document = new Document();
var page = document.Pages.Add();
// Create text fragment
//Width:{paragraph.Rectangle.Width}x{paragraph.Rectangle.Height} {paragraph.Rectangle.LLX}-{paragraph.Rectangle.LLY} x {paragraph.Rectangle.URX}-{paragraph.Rectangle.URY} 
TextFragment disclaimerFragment = new TextFragment();
disclaimerFragment.TextState.FontSize = 11; //if set to 7 my text fits
disclaimerFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.SlateGray);
disclaimerFragment.Text = $"{content}"; //content added from variable, large paragraph, 600 characters
page.Paragraphs.Add(disclaimerFragment);
document.Save(dataDir + "Test_19.4.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.