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

Free Support Forum - aspose.com

TOC does not run in the second run

Hi
Since version 6.0 we have the problem that the content directory has no page numbers and even more on links to the respective chapters. But only if you created a second document within the same start of the Exe.

In order to show better attached a code example.

		[TestMethod]
		public void DefaultFunctionsByAspose()
		{
			LicenseSetter.LicensePath = ConfigurationManager.AppSettings["Aspose.LicensePath"];
			LicenseSetter.SetLicense();
		BuildTestDoc(<SPAN style="COLOR: #a31515">@"c:/temp/TOC_Bookmark_Test.pdf"</SPAN>, <SPAN style="COLOR: #a31515">"Chapter {0}"</SPAN>);
		BuildTestDoc(<SPAN style="COLOR: #a31515">@"c:/temp/TOC_Bookmark_Test_2.pdf"</SPAN>, <SPAN style="COLOR: #a31515">"Kapitel {0}"</SPAN>);
		<SPAN style="COLOR: green">//BuildTestDoc(@"c:/temp/TOC_Bookmark_Test_2.pdf", "Chapter {0}");</SPAN>
	}

	<SPAN style="COLOR: blue">private</SPAN> <SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">void</SPAN> BuildTestDoc(<SPAN style="COLOR: blue">string</SPAN> storeTo, <SPAN style="COLOR: blue">string</SPAN> chapterLabel)
	{
		<SPAN style="COLOR: #2b91af">Pdf</SPAN> pdf1 = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Pdf</SPAN>();
		pdf1.IsBookmarked = <SPAN style="COLOR: blue">true</SPAN>;
		<SPAN style="COLOR: green">// set the value for Level of headings to be Bookmarked</SPAN>
		pdf1.BookmarkLevel = 5;
		<SPAN style="COLOR: green">//==========================================//</SPAN>
		<SPAN style="COLOR: green">// Create a Title page, add it to Bookmarks //</SPAN>
		<SPAN style="COLOR: green">//==========================================//</SPAN>
		Aspose.Pdf.Generator.<SPAN style="COLOR: #2b91af">Section</SPAN> sec1 = pdf1.Sections.Add();
		<SPAN style="COLOR: #2b91af">Heading</SPAN> Title_heading = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Heading</SPAN>(pdf1, sec1, 1);
		<SPAN style="COLOR: green">// create a segment for heading object</SPAN>
		<SPAN style="COLOR: #2b91af">Segment</SPAN> Title_segment = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Segment</SPAN>(Title_heading);
		<SPAN style="COLOR: green">// add the segment to segments collection of the Heading object</SPAN>
		Title_heading.Segments.Add(Title_segment);
		Title_segment.Content = <SPAN style="COLOR: #a31515">"Title Page"</SPAN>;
		Title_segment.TextInfo.Alignment = <SPAN style="COLOR: #2b91af">AlignmentType</SPAN>.Center;
		Title_segment.TextInfo.FontName = <SPAN style="COLOR: #a31515">"Arial"</SPAN>;
		Title_segment.TextInfo.FontSize = 20;
		<SPAN style="COLOR: green">// add heading to paragraphs collection of the TOC segment</SPAN>
		sec1.Paragraphs.Add(Title_heading);
		<SPAN style="COLOR: green">//============================================//</SPAN>
		<SPAN style="COLOR: green">// Create TOC - section and add to PDF object //</SPAN>
		<SPAN style="COLOR: green">//============================================//</SPAN>
		<SPAN style="COLOR: green">//Create List Section of type TOC </SPAN>
		<SPAN style="COLOR: #2b91af">ListSection</SPAN> tocSection = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">ListSection</SPAN>(pdf1);
		<SPAN style="COLOR: green">//Set its list type as table of of contents</SPAN>
		tocSection.ListType = <SPAN style="COLOR: #2b91af">ListType</SPAN>.TableOfContents;
		<SPAN style="COLOR: green">//Add the list section to the sections collection of the Pdf document</SPAN>
		pdf1.Sections.Add(tocSection);

		<SPAN style="COLOR: #2b91af">Heading</SPAN> heading1 = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Heading</SPAN>(pdf1, tocSection, 1);
		<SPAN style="COLOR: green">// create a segment for heading object</SPAN>
		<SPAN style="COLOR: #2b91af">Segment</SPAN> segment1 = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Segment</SPAN>(heading1);
		<SPAN style="COLOR: green">// add the segment to segments collection of the Heading object</SPAN>
		heading1.Segments.Add(segment1);
		segment1.Content = <SPAN style="COLOR: #a31515">"Table Of Contents"</SPAN>;
		segment1.TextInfo.Alignment = <SPAN style="COLOR: #2b91af">AlignmentType</SPAN>.Center;
		segment1.TextInfo.FontName = <SPAN style="COLOR: #a31515">"Arial"</SPAN>;
		segment1.TextInfo.FontSize = 20;
		<SPAN style="COLOR: green">// add heading to paragraphs collection of the TOC segment</SPAN>
		tocSection.Paragraphs.Add(heading1);
		<SPAN style="COLOR: blue">for</SPAN> (<SPAN style="COLOR: blue">int</SPAN> i = 1; i <= 10; i++)
		{
			<SPAN style="COLOR: #2b91af">Heading</SPAN> heading11 = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Heading</SPAN>(pdf1, tocSection, 2);
			<SPAN style="COLOR: green">// create a segment for heading object</SPAN>
			<SPAN style="COLOR: #2b91af">Segment</SPAN> segment11 = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Segment</SPAN>(heading11);
			segment11.Content = i.ToString() + <SPAN style="COLOR: #a31515">" - - - - - - - - - - - - - - - - - - - - - - - - Page "</SPAN> + i.ToString();
			<SPAN style="COLOR: green">// set the wordspace between words</SPAN>
			segment11.TextInfo.WordSpace = 4;
			<SPAN style="COLOR: green">// set the line space between two lines</SPAN>
			segment11.TextInfo.LineSpacing = 8;
		}


		<SPAN style="COLOR: blue">for</SPAN> (<SPAN style="COLOR: blue">int</SPAN> i = 0; i < 5; i++)
		{

			<SPAN style="COLOR: #2b91af">Section</SPAN> testSec = pdf1.Sections.Add();
			testSec.IsNewPage = <SPAN style="COLOR: blue">true</SPAN>;
			<SPAN style="COLOR: green">//Titel erstellen</SPAN>
			<SPAN style="COLOR: #2b91af">Heading</SPAN> head = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Heading</SPAN>(pdf1, testSec, 1);
			<SPAN style="COLOR: green">//head.ID = string.Format(chapterLabel, i);</SPAN>
			<SPAN style="COLOR: #2b91af">Segment</SPAN> seg = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Segment</SPAN>(head);
			head.Segments.Add(seg);
			<SPAN style="COLOR: green">//head.IsAutoSequence = true;</SPAN>
			seg.Content = <SPAN style="COLOR: blue">string</SPAN>.Format(chapterLabel, i);
			<SPAN style="COLOR: green">//seg.Content = "Titel";</SPAN>

			head.IsInList = <SPAN style="COLOR: blue">true</SPAN>;
			head.ID = seg.Content;
			testSec.Paragraphs.Add(head);
			head.IsAutoSequence = <SPAN style="COLOR: blue">true</SPAN>;

			<SPAN style="COLOR: green">//noch einen Text zu dem Kapitel</SPAN>
			<SPAN style="COLOR: #2b91af">Text</SPAN> label = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Text</SPAN>(<SPAN style="COLOR: blue">string</SPAN>.Format(<SPAN style="COLOR: #a31515">"i am the Content of '{0}'"</SPAN>, seg.Content));
			testSec.Paragraphs.Add(label);

			<SPAN style="COLOR: green">//and now add Sup Chapters</SPAN>
			<SPAN style="COLOR: blue">for</SPAN> (<SPAN style="COLOR: blue">int</SPAN> j = 0; j < 5; j++)
			{
				<SPAN style="COLOR: #2b91af">Section</SPAN> testSubSec = pdf1.Sections.Add();

				<SPAN style="COLOR: green">//Titel erstellen</SPAN>
				<SPAN style="COLOR: #2b91af">Heading</SPAN> headSub = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Heading</SPAN>(pdf1, testSubSec, 3);
				<SPAN style="COLOR: green">//head.ID = string.Format(chapterLabel, i);</SPAN>
				<SPAN style="COLOR: #2b91af">Segment</SPAN> segSub = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Segment</SPAN>(headSub);
				headSub.Segments.Add(segSub);
				<SPAN style="COLOR: green">//head.IsAutoSequence = true;</SPAN>
				segSub.Content = <SPAN style="COLOR: blue">string</SPAN>.Format(chapterLabel, <SPAN style="COLOR: blue">string</SPAN>.Format(<SPAN style="COLOR: #a31515">"{0}.{1}"</SPAN>, i, j));
				<SPAN style="COLOR: green">//seg.Content = "Titel";</SPAN>

				headSub.IsInList = <SPAN style="COLOR: blue">true</SPAN>;
				headSub.ID = segSub.Content;
				testSubSec.Paragraphs.Add(headSub);
				headSub.IsAutoSequence = <SPAN style="COLOR: blue">true</SPAN>;

				<SPAN style="COLOR: green">//noch einen Text zu dem Kapitel</SPAN>
				<SPAN style="COLOR: #2b91af">Text</SPAN> labelSub = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Text</SPAN>(<SPAN style="COLOR: blue">string</SPAN>.Format(<SPAN style="COLOR: #a31515">"i am the Content of '{0}'"</SPAN>, segSub.Content));
				testSubSec.Paragraphs.Add(labelSub);

			}
		}

		<SPAN style="COLOR: green">// Save the resultant PDF document</SPAN>
		pdf1.Save(storeTo);
		System.Diagnostics.<SPAN style="COLOR: #2b91af">Process</SPAN>.Start(storeTo);
	}

Regards Markus

Hello Markus,

Thanks for using our products.

I have tested the scenario and have managed to reproduce the same problem. The problem seems to be occurring after the two products have been merged. For the sake of correction, I have logged it as PDFNEWNET-29939 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

The issues you have found earlier (filed as 29939) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.