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

Free Support Forum - aspose.com

Heading.TextState.ForegroundColor not working in 10.9.0 - 11.5.0

Hi,


We currently have code to add a TOC to an existing PDF and part of that is setting different colors for different headings in the TOC. In Aspose PDF 10.8.0 this works fine but in any version above that it fails to change the color.

I have managed to duplicate the same issue in a small test example (code originally from TOC formatting issues)

See below - setting heading2.TextState.ForegroundColor doesn’t change the output color in the TOC. This code works fine in 10.8.0 though.
var license = new License();
license.SetLicense(“Aspose.Pdf.lic”);
Document doc = new Document(@“D:\temp\TocError\test.pdf”);

// Get access to first page of PDF file
Page tocPage = doc.Pages.Insert(1);

// Create object to represent TOC information
TocInfo tocInfo = new TocInfo();
TextFragment title = new TextFragment(“Table Of Contents”);
title.TextState.FontSize = 15;
title.TextState.FontStyle = FontStyles.Bold;
title.TextState.ForegroundColor = Color.Red;

// Align : Left didn’t work in our case
title.TextState.HorizontalAlignment = HorizontalAlignment.Left;

// Set the title for TOC
tocInfo.Title = title;
tocPage.TocInfo = tocInfo;

// Create string objects which will be used as TOC elements
string[] titles = new string[5];
titles[0] = “English - Testing Header one”;
titles[1] = “English - Testing Header two”;
titles[2] = “English - Testing Header three”;
titles[3] = “English - Testing Header four”;
titles[4] = “English - Testing Header fives”;
for (int i = 0; i < 5; i++)
{
// Create Heading object
Heading heading2 = new Heading(i == 2 || i == 4 ? 2 : 1);
TextSegment segment2 = new TextSegment();
segment2.TextState.FontStyle = FontStyles.Italic;
segment2.TextState.ForegroundColor = (i % 2) == 0 ? Color.Red : Color.Blue;
heading2.TextState.ForegroundColor = (i % 2) == 0 ? Color.Red : Color.Blue;
heading2.TocPage = tocPage;
segment2.TextState.LineSpacing = 12;
heading2.Segments.Add(segment2);

<span style="color:green;">// Specify the destination page for heading object</span>
heading2.<span style="color:purple;">DestinationPage</span> = doc.<span style="color:purple;">Pages</span>[<span style="font-weight:bold;">i</span> + 2];

<span style="color:green;">// Destination page</span>
heading2.<span style="color:purple;">Top</span> = doc.<span style="color:purple;">Pages</span>[<span style="font-weight:bold;">i</span> + 2].<span style="color:purple;">Rect</span>.<span style="color:purple;">Height</span>;

<span style="color:green;">// Destination coordinate</span>
segment2.<span style="color:purple;">Text</span> = titles[<span style="font-weight:bold;">i</span>];

<span style="color:green;">// Add heading to page containing TOC</span>
tocPage.<span style="color:purple;">Paragraphs</span>.<span style="color:darkcyan;">Add</span>(heading2);

}

// Save the updated document
doc.Save(@“D:\temp\TocError\test-output2.pdf”);

Hi Chris,

Thanks for your inquiry. I have tested your shared code with Aspose.Pdf for .NET 10.8.0 and Aspose.Pdf for .NET 11.5.0 and managed to observe the reported regression issue. For further investigation, I have logged a regression issue in our issue tracking system as PDFNEWNET-40589 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-40589) have been fixed in Aspose.Pdf for .NET 11.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Thanks - we have downloaded the new version and this is all working great now.


Cheers
Chris

Hi Chris,


Thanks for your feedback. It is good to know that you have managed to resolve the issue with latest release.

Please feel free to contact us for any further query or concern, we will be more than happy to extend our support.

Best Regards,