Free Support Forum - aspose.com

TOC level format issue

Hello,


1. We need to generate PDF document with the hierarchical TOC (let us say 2 levels). Here it is our sample code:

Document document = new Document();

Page tocPage = document.Pages.Add();
tocPage.PageInfo = new PageInfo
{
Margin = new MarginInfo { Bottom = 0, Left = 0, Right = 0, Top = 0 }
};
tocPage.TocInfo = new TocInfo()
{
Title = new TextFragment(“Table of Contents”),
};

Page docPage = document.Pages.Add();
docPage.PageInfo = new PageInfo
{
Margin = new MarginInfo { Bottom = 0, Left = 0, Right = 0, Top = 0 }
};


Heading h1 = new Heading(1);
h1.Text = “test 1”;
h1.IsAutoSequence = true;
h1.IsInList = true;
h1.TocPage = tocPage;
docPage.Paragraphs.Add(h1);

Heading h11 = new Heading(2);
h11.Text = “test 1.1”;
h11.IsAutoSequence = true;
h11.IsInList = true;
h11.TocPage = tocPage;
docPage.Paragraphs.Add(h11);

Heading h12 = new Heading(2);
h12.Text = “test 1.2”;
h12.IsAutoSequence = true;
h12.IsInList = true;
h12.TocPage = tocPage;
docPage.Paragraphs.Add(h12);

Heading h2 = new Heading(1);
h2.Text = “test 2”;
h2.IsAutoSequence = true;
h2.IsInList = true;
h2.TocPage = tocPage;
docPage.Paragraphs.Add(h2);

tocPage.TocInfo.FormatArrayLength = 5; // assume 5 levels max
for (int index = 0; index < tocPage.TocInfo.FormatArray.Length; index++)
{
LevelFormat lf = tocPage.TocInfo.FormatArray[index];
lf.Margin.Left = (index + 1)*10; // set indent for every level (+ 10 for every level)
}

document.Save(“output.pdf”);

The expected output TOC hierarchy is:

1. test 1
1.1 test 1.1
1.2 test 1.2
2. test 2

Auto-sequence numbers are generated properly but the margin is wrong. For the 1st level it should be 10, for the 2nd - 20 etc. However it seems that the margin that we defined for different level formats are ignored. Moreover, we defined heading for only 2 levels, but the margin for the last record is TOC is 40 and that corresponds to the level 4.

Please let us know what we did wrong and advise how to generate the required output.

**************************************

2. One more issue found. If we just add many headings to a page the “Null Reference” exception is raised on a document save:

for (int i = 0; i < 100; i++)
{
Heading h1 = new Heading(1)
{
Text = "test " + i.ToString(),
IsAutoSequence = true,
IsInList = true,
TocPage = tocPage
};
docPage.Paragraphs.Add(h1);
}

Our document may contain more than 100 heading. Also when we did the same using your “Generator” API everything worked as expected without exceptions.
Please comment.
Hi Dmitry,


ShmelP:
Hello,

1. We need to generate PDF document with the hierarchical TOC (let us say 2 levels). Here it is our sample code:

Document document = new Document();

Page tocPage = document.Pages.Add();
tocPage.PageInfo = new PageInfo
{
Margin = new MarginInfo { Bottom = 0, Left = 0, Right = 0, Top = 0 }
};
tocPage.TocInfo = new TocInfo()
{
Title = new TextFragment("Table of Contents"),
};

Page docPage = document.Pages.Add();
docPage.PageInfo = new PageInfo
{
Margin = new MarginInfo { Bottom = 0, Left = 0, Right = 0, Top = 0 }
};


Heading h1 = new Heading(1);
h1.Text = "test 1";
h1.IsAutoSequence = true;
h1.IsInList = true;
h1.TocPage = tocPage;
docPage.Paragraphs.Add(h1);

Heading h11 = new Heading(2);
h11.Text = "test 1.1";
h11.IsAutoSequence = true;
h11.IsInList = true;
h11.TocPage = tocPage;
docPage.Paragraphs.Add(h11);

Heading h12 = new Heading(2);
h12.Text = "test 1.2";
h12.IsAutoSequence = true;
h12.IsInList = true;
h12.TocPage = tocPage;
docPage.Paragraphs.Add(h12);

Heading h2 = new Heading(1);
h2.Text = "test 2";
h2.IsAutoSequence = true;
h2.IsInList = true;
h2.TocPage = tocPage;
docPage.Paragraphs.Add(h2);

tocPage.TocInfo.FormatArrayLength = 5; // assume 5 levels max
for (int index = 0; index < tocPage.TocInfo.FormatArray.Length; index++)
{
LevelFormat lf = tocPage.TocInfo.FormatArray[index];
lf.Margin.Left = (index + 1)*10; // set indent for every level (+ 10 for every level)
}

document.Save("output.pdf");

The expected output TOC hierarchy is:

1. test 1
1.1 test 1.1
1.2 test 1.2
2. test 2

Auto-sequence numbers are generated properly but the margin is wrong. For the 1st level it should be 10, for the 2nd - 20 etc. However it seems that the margin that we defined for different level formats are ignored. Moreover, we defined heading for only 2 levels, but the margin for the last record is TOC is 40 and that corresponds to the level 4.

Please let us know what we did wrong and advise how to generate the required output.

**************************************


Thanks for your inquiry. I have noticed the reported issue and logged an investigation ticket PDFNEWNET-39007 for further investigation and rectification. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,
ShmelP:

2. One more issue found. If we just add many headings to a page the "Null Reference" exception is raised on a document save:

for (int i = 0; i < 100; i++)
{
Heading h1 = new Heading(1)
{
Text = "test " + i.ToString(),
IsAutoSequence = true,
IsInList = true,
TocPage = tocPage
};
docPage.Paragraphs.Add(h1);
}

Our document may contain more than 100 heading. Also when we did the same using your "Generator" API everything worked as expected without exceptions.
Please comment.

Hi Dmitry,

We have noticed that too many TOC entries throws Null Reference exception, so logged a ticket PDFNEWNET-39008 for further investigation and rectification. We will notify you as soon as it is resolved.

Moreover in reference to old generator(Aspose.Pdf.Generator), it has some other major issues so we introduced new generator. However, we have logged your above issues with high priority so these can be addressed asap.

We are sorry for the inconvenience caused.

Best Regards,

Thanks for your inquiry. I have noticed the reported issue and logged an investigation ticket PDFNEWNET-39007 for further investigation and rectification. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,

Please note that in your documentation (http://www.aspose.com/docs/display/pdfnet/Manipulating+List+of+Contents) you explain how to apply styles to different TOC levels. In your new generator it does not work as you describe it, however in answers to my other posts you highly recommend to use the new approach. I believe that it's the critical issue when API does not work as it should according to the documentation and tutorials (especially in production and rather expensive products as the Aspose is). So please set the high priority to this issue and resolve it ASAP, because it's the blocker. In the current version it's not possible to create a hierarchical TOC with many levels and many headings, but real PDF files may contain hundreds headings and appropriate TOC references.
Hi Dmitry,

We are sorry for the inconvenience. We have already logged issue with high priority and requested our product team to share an ETA at their earliest. We will keep you updated about the issue resolution progress.

Best Regards,

Hi Dmitry,


Thanks for your patience.

We are pleased to share that the issues reported earlier in this thread are resolved and their resolution will be included in next release of Aspose.Pdf for .NET 10.7.0, which is planned to release in August-2015. Please be patient and wait for the resolution.

The issues you have found earlier (filed as PDFNEWNET-39008;PDFNEWNET-39007) have been fixed in Aspose.Pdf for .NET 10.7.0.


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