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.
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.