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

Free Support Forum - aspose.com

TextFragment no text break

Hi Support,

I have following code, which is dividing the page into 3 columns and adds data into that columns from a list.
How can I force that the text in second text fragment never breaks? I don’t want a part of the text be in one column and the rest in the next column.

If it’s not possible with TextFragment object, what else can I use to achieve this?

Thank you !

    FloatingBox box = new FloatingBox();
    box.ColumnInfo.ColumnCount = 3;

    foreach (var member in members)        
         {
            TextFragment tf_name = new TextFragment(member.MemberName.ToUpper());
            tf_name.TextState.FontSize = 13;
            tf_name.TextState.FontStyle = FontStyles.Bold;
            tf_name.TextState.ForegroundColor = Color.FromArgb(32, 148, 185);
            tf_name.Margin.Top = 10;
            tf_name.Margin.Bottom = 3;
            tf_name.IsKeptWithNext = true;

            TextFragment tf_role = new TextFragment(member.MemberRoleDesc);
            tf_role.TextState.FontSize = 9;
            tf_role.TextState.LineSpacing = 2;
            tf_role.TextState.ForegroundColor = Color.Black;
            
            box.Paragraphs.Add(tf_name);
            box.Paragraphs.Add(tf_role);
        }
     page.Paragraphs.Add(box);

@vardanho

Thanks for contacting support.

You can use IsInLineParagraph property of TextFragment, which keeps TextFragment in line, when set to true. Please check following code snippet and attached output, where second TextFragment is in the same line of its respective first TextFragment.

Document doc = new Document();
Page page = doc.Pages.Add();
FloatingBox box = new FloatingBox();
box.ColumnInfo.ColumnCount = 3;
List<Member> members = new List<Annotations.Member>();
members.Add(new Member { MemberName = "John Doe", MemberRoleDesc = "Manager" });
members.Add(new Member { MemberName = "Jane Doe", MemberRoleDesc = "Assistant Manager" });
foreach (var member in members)
{
 TextFragment tf_name = new TextFragment(member.MemberName.ToUpper());
 tf_name.TextState.FontSize = 13;
 tf_name.TextState.FontStyle = FontStyles.Bold;
 tf_name.TextState.ForegroundColor = Color.FromArgb(32, 148, 185);
 tf_name.Margin.Top = 10;
 tf_name.Margin.Bottom = 3;
 tf_name.IsKeptWithNext = true;

 TextFragment tf_role = new TextFragment(member.MemberRoleDesc);
 tf_role.TextState.FontSize = 9;
 tf_role.TextState.LineSpacing = 2;
 tf_role.TextState.ForegroundColor = Color.Black;
 tf_role.IsInLineParagraph = true;

 box.Paragraphs.Add(tf_name);
 box.Paragraphs.Add(tf_role);
}
page.Paragraphs.Add(box);
doc.Save(dataDir + "TextFragmentBreak.pdf");

The Class, which was used in above code snippet, is as follows:

class Member
{
 public string MemberName { get; set; }
 public string MemberRoleDesc { get; set; }
}

In case of any further assistance, please feel free to contact us.

TextFragmentBreak.pdf (2.4 KB)

Hi @asad.ali,

Thanks for quick reply.

A couple of problems with that approach

  1. When I set the IsInLineParagraph = true; it cuts the text right where the page ends and does not display the second part of the text
  2. It indents the text in TextFragment (see screenshot)

What I’m looking for is in case there is long text and cannot fit at the end in column 1 that whole section with name and role shifts to the column 2 leaving empty space at column 1.
Any other ideas?

TextIndent.png (15.3 KB)

Thank You !

P.S. Your provided link is not working for me, errors out with HTTP ERROR 500

@vardanho

Thanks for writing back.

Please make sure that you are logged in before downloading the files. In case if you still face any issue in downloading the files, please let us know, so that we can investigation the reasons and address them accordingly.

We are checking details in this regard and will get back to you shortly. Please be patient.

Yep, I’m logged in and still getting the same error on chrome. Tried on firefox as well, and getting blank screen.
But this is not important at this point.

@vardanho

Thanks for your patience.

I have tested the scenario again with long text and observed that the text in second text fragment overlapped with its respective text fragment at line break. Hence I have logged this issue as PDFNET-43062 in our issue tracking system.

I have also logged an investigation ticket as PDFNET-43063 in our issue tracking system for your requirement. Our product team will further investigate these logged issues and as soon as we receive any updates regarding resolution progress, we will certainly inform you within this thread. Please be patient and spare us little time.

We are sorry for the inconvenience.