Free Support Forum - aspose.com

Using unicode characters in TOC and Bookmarks

Hello,

After saving pdf with SetUnicode(), the body of resulting pdf is displayed properly with all unicode characters, but TOC and Bookmarks don't display some unicode characters.

Thank you.

Jozef.

Hello Jozef,

Thanks for using our products.

I have tested the scenario using Aspose.Pdf for .NET 5.0.0 using the following code snippet and I am unable to notice any problem. The Unicode characters are properly being displayed in both TOC and Bookmark section. Can you please share the code snippet that you are using so that we can test the scenario at our end. We apologize for your inconvenience.

[C#]

// Instantiate an object PDF class
Pdf pdf = new Pdf();
pdf.IsBookmarked = true;
pdf.BookMarkLevel = 1;

//Create a list section
ListSection tocSection = new ListSection("Table Of Contents");
//Set its list type as table of of contents
tocSection.ListType = ListType.TableOfContents;
//Add the list section to the sections collection of the Pdf document
pdf.Sections.Add(tocSection);

//Define the format of the four levels list by setting the left margins and
/text format settings of each level
tocSection.ListFormatArray.Length = 4;
tocSection.ListFormatArray[0].LeftMargin = 0;
tocSection.ListFormatArray[0].TextInfo.IsTrueTypeFontBold = true;
tocSection.ListFormatArray[0].TextInfo.IsTrueTypeFontItalic = true;
tocSection.ListFormatArray[1].LeftMargin = 10;
tocSection.ListFormatArray[1].TextInfo.IsUnderline = true;
tocSection.ListFormatArray[1].TextInfo.FontSize = 10;
tocSection.ListFormatArray[2].LeftMargin = 20;
tocSection.ListFormatArray[2].TextInfo.IsTrueTypeFontBold = true;
tocSection.ListFormatArray[3].LeftMargin = 30;
tocSection.ListFormatArray[3].TextInfo.IsTrueTypeFontBold = true;

//Create a section in the Pdf document
Section sec1 = pdf.Sections.Add();
//Add four headings in the section
for (int Level = 1; Level < 5; Level++)
{
Heading heading2 = new Heading(pdf, sec1, Level);
Segment segment2 = new Segment(heading2);
heading2.Segments.Add(segment2);
heading2.IsAutoSequence = true;
segment2.Content = "this is heading of level #$UNICODE(197) ";
segment2.Content += Level.ToString();
//Add the heading into Table Of Contents.
heading2.IsInList = true;
sec1.Paragraphs.Add(heading2);
}

// save the Pdf file
pdf.Save(@"d:\pdftest\UniCode_Test.pdf");

Hello,

thanks for the answer.

I'm using Slovak characters in pdf. All slovak characters are displayed properly in pdf except TOC and Bookmark. I have edited your code to vb.net. Changes are highlighted by yellow color.

Here is my code:

'Instantiate an object PDF class

Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()

pdf.IsBookmarked = True

''pdf.BookMarkLevel = 1

'Create a list section

Dim tocSection As Aspose.Pdf.ListSection = New Aspose.Pdf.ListSection("Table Of Contents")

'Set its list type as table of of contents

tocSection.ListType = Aspose.Pdf.ListType.TableOfContents

'Add the list section to the sections collection of the Pdf document

pdf.Sections.Add(tocSection)

'Define the format of the four levels list by setting the left margins

'and

'text format settings of each level

tocSection.ListFormatArray.Length = 4

tocSection.ListFormatArray(0).LeftMargin = 0

tocSection.ListFormatArray(0).Margin.Right = 30

tocSection.ListFormatArray(0).TextInfo.IsTrueTypeFontBold = True

tocSection.ListFormatArray(0).TextInfo.IsTrueTypeFontItalic = True

tocSection.ListFormatArray(1).LeftMargin = 10

tocSection.ListFormatArray(1).Margin.Right = 30

tocSection.ListFormatArray(1).TextInfo.IsUnderline = True

tocSection.ListFormatArray(1).TextInfo.FontSize = 10

tocSection.ListFormatArray(2).LeftMargin = 20

tocSection.ListFormatArray(2).Margin.Right = 30

tocSection.ListFormatArray(2).TextInfo.IsTrueTypeFontBold = True

tocSection.ListFormatArray(3).LeftMargin = 30

tocSection.ListFormatArray(3).Margin.Right = 30

tocSection.ListFormatArray(3).TextInfo.IsTrueTypeFontBold = True

'Create a section in the Pdf document

Dim sec1 As Aspose.Pdf.Section = pdf.Sections.Add()

'Add four headings in the section

For Level = 1 To 4

Dim heading2 As Aspose.Pdf.Heading = New Aspose.Pdf.Heading(pdf, sec1, Level)

Dim segment2 As Aspose.Pdf.Segment = New Aspose.Pdf.Segment(heading2)

heading2.Segments.Add(segment2)

heading2.IsAutoSequence = True

''segment2.Content = "this is heading of level #$UNICODE(197) "

segment2.Content = "Problematic characters are: ľ,č,ť,ň,... "

segment2.Content += Level.ToString()

'Add the heading into Table Of Contents.

heading2.IsInList = True

sec1.Paragraphs.Add(heading2)

Next

' save the Pdf file

pdf.SetUnicode()

pdf.Save("d:\UniCode_My_Test.pdf")

I have also attached my resulting pdf file, where you can see differencies between TOC and body.

... and one more question regarding TOC alignment. How can I align TOC on the right? As you can see I have added tocSection.ListFormatArray(0).Margin.Right = 30 to my code, but it looks that it ignored.

Thanks, Jozef.

Hello Jozef,

Thanks for sharing the code snippet.

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNET-24899. We will investigate this issue in details and will keep you updated on the status of a correction. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We apologize for your inconvenience.

Hello,


Is there any update on this ticket (PDFNET-24899) ?

We are experiencing the same issue : the Chinese text is rendered correctly in the PDF body but not in the TOC. We are using the font “Arial Unicode MS”.

The version is Aspose PDF .NET v6.8.0.0

Thanks,

Serguei

Hi Serguei,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have tested the latest version and issue related to TOC is still not resolved (bookmarks are however showing properly). I have registered an issue in our issue tracking system with issue id: PDFNEWNET-34625. Our development team will further look into this issue and we will update you via this forum thread.

Sorry for the inconvenience,

Hi Serguei,


Thanks for your patience.

We have further investigated the issue PDFNEWNET-34625 and as per our observations, in order to resolve this problem, please try using following code lines.

tocSection.ListFormatArray(3).TextInfo.IsTrueTypeFontBold = true;
tocSection.ListFormatArray(3).TextInfo.FontName = “Arial Unicode MS”;

As “Arial Unicode MS” is regular, not bold TTF font, so IsTrueTypeFontBold is just ignored - it’s a behavior by design in Aspose.Pdf.Generator. Besides this, you may also consider using following code snippet to generate the correct output. The following code snippet with work with upcoming release of Aspose.Pdf for .NET 8.0.0 which is planned to release in current week.

[C#]

Document doc = new
Document();<o:p></o:p>

Page tocPage = doc.Pages.Add();

TOCInfo tocInfo = new TOCInfo();

TextFragment title = new TextFragment("Table Of Contents");

title.TextState.FontSize = 30;

tocInfo.Title = title;

//Add the list section to the sections collection of the Pdf document

tocPage.TOCInfo = tocInfo;

//Define the format of the four levels list by setting the left margins

//and

//text format settings of each level

tocInfo.FormatArrayLength = 4;

tocInfo.FormatArray[0].Margin.Left = 0;

tocInfo.FormatArray[0].Margin.Right = 30;

tocInfo.FormatArray[0].TextState.FontStyle = FontStyles.Bold | FontStyles.Italic;

//tocSection.ListFormatArray(0).TextInfo.FontName = "Arial Unicode MS"

tocInfo.FormatArray[1].Margin.Left = 10;

tocInfo.FormatArray[1].Margin.Right = 30;

tocInfo.FormatArray[1].TextState.Underline = true;

tocInfo.FormatArray[1].TextState.FontSize = 10;

tocInfo.FormatArray[2].Margin.Left = 20;

tocInfo.FormatArray[2].Margin.Right = 30;

tocInfo.FormatArray[2].TextState.FontStyle = FontStyles.Bold;

tocInfo.FormatArray[3].Margin.Left = 30;

tocInfo.FormatArray[3].Margin.Right = 30;

tocInfo.FormatArray[3].TextState.FontStyle = FontStyles.Bold;

//Create a section in the Pdf document

Page page = doc.Pages.Add();

//Add four headings in the section

for (int Level = 1; Level <= 4; Level++)

{ Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(Level);

TextSegment segment2 = new TextSegment();

heading2.Segments.Add(segment2);

heading2.IsAutoSequence = true;

heading2.TOCPage = tocPage;

segment2.Text = "汉字/漢字" + Level;

heading2.TextState.Font = FontRepository.FindFont("Arial Unicode MS");

//Add the heading into Table Of Contents.

heading2.IsInList = true;

page.Paragraphs.Add(heading2);

}

// save the Pdf fileoutFile

doc.Save(“c:/pdftest/TOCIssue.pdf”);

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


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