Can we create Table of content for Pdf document in aspose? If yes, Please can you guide me how?
Hi Aneesh,
I’m sorry to inform you that creating a table of contents in an existing PDF file is currently not supported. However, if you could elaborate your requirement that how you would like to create a TOC then we’ll try to support this feature in our future versions.
We’re sorry for the inconvenience.
Regards,
Pdf pdf = new Pdf();
pdf.IsBookmarked = true;
pdf.BookMarkLevel = 2;
ListSection TOCSection = new ListSection(pdf);
TOCSection.ListType = ListType.TableOfContents;
Text SText = new Text("Table Of Content");
TOCSection.Title = SText;
TOCSection.Title.TextInfo.Alignment = AlignmentType.Center;
TOCSection.Title.TextInfo.FontSize = 20;
pdf.Sections.Add(TOCSection);
Aspose.Pdf.Section Chapter;for (int i = 0; i < 2; i++)
{
Chapter = pdf.Sections.Add();
Heading Chapter_heading = new Heading(pdf,Chapter,1);
Chapter_heading.HeadingType = HeadingType.Arab;
Segment Chapter_segment = new Segment(Chapter_heading);
Chapter_heading.Segments.Add(Chapter_segment);
Chapter_segment.Content = string.Format("Sample Chapter {0}", i);
Chapter_heading.IsInList = true;
Chapter_heading.IsAutoSequence = true;
Chapter.Paragraphs.Add(Chapter_heading);
Text Sample_Text = new Text("Sample text for Chapter");Chapter.Paragraphs.Add(Sample_Text);
}
pdf.Save(@"D:/TOC.pdf");
Hi Aneesh,
The code you have shared is related to Aspose.Pdf, which allows you to create the PDF files from scratch. It doesn’t allow you to add table of content in an existing PDF file. Are you trying to create the TOC in a new PDF file or you want to add it to an existing PDF file? If you’re trying to add TOC in an existing PDF file as in above post, are you having some issue?
We’re sorry for the inconvenience and looking forward to help you out.
Regards,
I have requirement where I have to merge muiltiple files (*.doc, *.pdf, *.ppt, *.xls) and create a new PDf file with Table Of Content for it. Can you help me with that? I have used the follwoing code:
Pdf pdf = new Pdf();
pdf.IsBookmarked = true;
pdf.BookMarkLevel = 2;
ListSection TOCSection = new ListSection(pdf);
TOCSection.ListType = ListType.TableOfContents;
Text SText = new Text("Table Of Content");
TOCSection.Title = SText;
TOCSection.Title.TextInfo.Alignment = AlignmentType.Center;
TOCSection.Title.TextInfo.FontSize = 20;
pdf.Sections.Add(TOCSection);
Aspose.Pdf.Section Chapter;
for (int i = 0; i < 1; i++)
{
Chapter = pdf.Sections.Add();
Heading Chapter_heading = new Heading(pdf,Chapter,1);
Chapter_heading.HeadingType = HeadingType.Arab;
Segment Chapter_segment = new Segment(Chapter_heading);
Chapter_heading.Segments.Add(Chapter_segment);
Chapter_segment.Content = string.Format("Sample Chapter {0}", i);
Chapter_heading.IsInList = true;
Chapter_heading.IsAutoSequence = true;
Chapter.Paragraphs.Add(Chapter_heading);
FileStream inStream = new FileStream(@"D:\Dashboard 1.20_StatusPlate.pdf", FileMode.Open);
Text Sample_Text = new Text("Sample text for Chapter");
Chapter.Paragraphs.Add(Sample_Text);
}
pdf.Save(@"D:/TOC.pdf");
Instead of text entered in Chapters I want to add contents from files.
Hi Aneesh,
This query looks similar to your other question. Please have a look at the answer on the other thread at this link.
Regards,
I have muiltiple PDf files and want to merger them. It works fine for file with small size but fails for files with larger size. I tried with four version of dlls and following are the out come of the same.
3.7.0.0 version .... cannot open the larger files.
4.7.0.0 version .... Opens the file and executes the code without exception but final Pdf file generated cannot be opened as it says damaged.
4.8.0.0 version .... Open the files but exception occurs while merging the PDFs. Exception: Getting error trying to Concatenate: Unable to cast object of type 'xeb116a323308e2f7.xae94bcfc1c7ddd9a' to type 'xeb116a323308e2f7.x0b25947bdf0fba40'.
4.9.0.0 version .... Open the files but exception occurs while merging the PDFs. Exception: Getting error trying to Concatenate: Unable to cast object of type 'xeb116a323308e2f7.xae94bcfc1c7ddd9a' to type 'xeb116a323308e2f7.x0b25947bdf0fba40'.
Can you please suggest me the solution for it.
Hi Aneesh,
Please share the sample input PDF files along with the code snippet you’re using at your end. We’ll test the issue over here and update you accordingly.
We’re sorry for the inconvenience.
Regards,
The link provided to create TOC doesn’t exist
@ranjeeta_balakrishna,
Please try the following code example: Concatenate PDF files and create Table of Contents