Major issue introduced in 20.7 - Text Segment TextState ignored

A fairly major bug has been introduced into Aspose PDF 20.7 and above. 20.6 and below work fine. This is a bug as we have iterated through each package since 19.x successfully and written code against this feature - which is also documented on this site.

If a TextFragment has any TextState attributed to it (For example setting it to a normal font style or specific color), and then you add or append any TextSegments which have their own TextStyles defined, these are then ignored and the entire fragment renders using the parent style.

This means that it is now impossible to have a Text Fragment and alter the style of a subset of it (For our usage we iterate over paragraphs and make certain words bold)

The code for this is below to replicate

  Document pdfDocument = new Document();
  Page pdfPage = (Page)pdfDocument.Pages.Add();

  var t = new TextFragment();
  t.TextState.FontStyle = FontStyles.Regular;
  t.TextState.ForegroundColor = Color.Blue;      
  var boldText = new TextSegment("I am red bold text.");
  boldText.TextState.FontStyle = FontStyles.Bold;
  boldText.TextState.ForegroundColor = Color.Red;
  var normalText = new TextSegment("I am normal text.");      
  t.Segments.Add(boldText);
  t.Segments.Add(normalText);
  pdfPage.Paragraphs.Add(t);
  pdfDocument.Save(@"C:\TEMP\ASPOSE.PDF");

In a working scenario this would yield

I am red bold text.I am normal text. (In red and blue)
Since 20.7 this yields
I am red bold text.I am normal text. , (all in blue)

As we have built a rather extensive tagging library around this feature for a large enterprise application this is fairly critical, and given that we have just renewed our licence and are unable to upgrade to accept other bug fixes this is now a blocker.

As a temporary measure I can stay on 20.7 but would need Aspose to fix this ASAP or refund part of the newly upgraded licence as we are unable to upgrade to the latest software due to this bug - Unless another workaround can be provided.

@R_C_D_T

We really apologize for the inconvenience you have been facing due to this issue. We were able to replicate the bug in our environment and logged it as PDFNET-48777 in our issue management system. We have also recorded your concerns and will keep them in view during investigation against the ticket. We will inform you as soon as we make some certain progress towards its resolution. Please give us some time.

We again apologize for the inconvenience.

Is there any update on this as we cannot upgrade to this months release to get another fix without this issue being present.

@R_C_D_T

We are afraid that earlier logged ticket is not yet resolved. We will surely investigate and resolve it on first come first serve basis. Once the investigation against it is completed, we will be able to share some updates with you regarding its resolution ETA. Please be patient and give us some time.

We are sorry for the inconvenience.

Is there any indication of the position in the queue for this?

As Aspose introduced this bug in 20.7 it means that we cannot update our system to use the latest versions
This means that we cannot make use of other fixes since 20.7, and more frustratingly we are paying a licence to cover 12 months of upgrades that we cannot accept

If this was an obscure issue I would understand having to wait, but as Aspose introduced this bug due to lack of testing this should be prioritized or a license renegotiation should occur - which your sales team don’t seem to understand.

@R_C_D_T

We are collecting the information regarding investigation results against the logged ticket and will soon try to share some ETA with you. We do understand the severity of the issue for you and humbly apologize for the inconvenience being faced. We have raised the issue priority to next level while considering your concerns. We will let you know soon about further updates. Please give us little time.

We are sorry for the delay and inconvenience.

@R_C_D_T

We would like to inform you that issue has been scheduled for investigation during next week and as soon as the analysis is completed, we will share updates about its ETA with you.

1 Like

I see that the item has been resolved, am I correct in thinking this will be in the 20.12 release which is imminent?

@R_C_D_T

Yes, you are right. The ticket has been fixed and will be included in upcoming release 20.12. We will update within this forum thread as soon as new release is available.

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

This issue appeared again in v24.9.0 (aspose pdf - C#),

it is supposed to work or is it a dismissed feature?

As a (sadly) veteran of this software I am not shocked. We went almost a year before we could update as Aspose do not test their software which is disgusting for the price we pay.
Even this year we cannot upgrade past 24.5.1 as there are random issues with text getting underlined at random

So much so that I am currently mid-proposal for ditching almost 20k of licences for Aspose for another platform. Its genuinely ridiculous.

@R_C_D_T @Red192

We sincerely apologize for the inconvenience caused. Please note that many times issues are related to specific PDF document and they are resolved only for those particular files. Also, the regression issues are taken seriously and we try our best to resolve them at our earliest. The API has a lot of modules and they can sometimes produce unexpected results due to other modules on which they are dependent. The detailed investigation is carried out in such cases and we fix the issues.

Nevertheless, are you facing this issue with .NET Core or .NET Framework?

Thanks @asad.ali, i’m experiecing the issue in .net 8.
If you are confirming it was still an expected behavior, should i open a bug for it?

@Red192

Please try using Aspose.Pdf.Drawing instead of Aspose.PDF for .NET and see if this issue still persists.

It’s not possible to use pdf.Drawing alone

@Red192

Can you please share why you cannot use Aspose.Pdf.Drawing alone? It has all the features and Classes that Aspose.PDF for .NET has. Is there some kind of limitation at your end?

using var doc = new Document();

using var page = doc.Pages.Add();

TabStops ts = new TabStops();


TabStop ts1 = ts.Add(0);
ts1.AlignmentType = TabAlignmentType.Left;
ts1.LeaderType = TabLeaderType.None;

TabStop ts2 = ts.Add(70);
ts2.AlignmentType = TabAlignmentType.Left;
ts2.LeaderType = TabLeaderType.None;

TabStop ts3 = ts.Add(220);
ts3.AlignmentType = TabAlignmentType.Left;
ts3.LeaderType = TabLeaderType.None;

TabStop ts4 = ts.Add(290);
ts4.AlignmentType = TabAlignmentType.Left;
ts4.LeaderType = TabLeaderType.None;
var segm = new[] {
	new[]{"First", "Second", "third", "fourth"},
	new[]{"First", "Second"},
};
foreach (var i in segm)
{
	TextFragment text0 = new TextFragment(ts);
	text0.HorizontalAlignment = HorizontalAlignment.Left;
	var jj = true;
	foreach (var x in i)
	{
		var seg = new TextSegment(x + "#$TAB");
		seg.TextState = new TextState()
		{
			FontStyle = jj ? FontStyles.Bold : FontStyles.Regular,
			FontSize = jj ? 15 : 8,
		};
		jj = jj != true;
		text0.Segments.Add(seg);
	}
	page.Paragraphs.Add(text0);
}

doc.Save("C:\\Users\\InvoiceTest34.pdf");

for example. To use this you have to reference

Aspose.Pdf
Aspose.Pdf.Text

@Red192

There should be no issue with these namespaces. Please note that Aspose.Pdf.Drawing is a version of Aspose.PDF for .NET that has all Classes of the original API except it does not have any dependency upon System.Drawing.Common Assembly (other than the printing features). Therefore, you can easily uninstall existing package and install Aspose.Pdf.Drawing package from NuGet Gallery and your above code will not give any error.

I did @asad.ali, using Aspose.Pdf.Drawing it’s equivalent on using Aspose.Pdf in mater of it’s namespaces, since it’s a referenced package. The problem persist. You can try it yourself using the snippet i sent you