Free Support Forum - aspose.com

Error on save pdf more than 7 chapter level

we found out that pdf.save() produces an “file already used by another process” whenever a pdf document having more than 7 chapter level is generated with TOC using aspose pdf. Up to 7 level is works fine

Hi Pascal,


Thanks for using our products.

I have tested the scenario using Aspose.Pdf for .NET 7.7.0 over Windows 7 (X64) where I have used Visual Studio 2010 project and I am unable to notice any issue. I have used the following code snippet. Can you please share the code snippet that you are using or update the following code snippet so that we can replicate this issue at our end. We are really sorry for your inconvenience.

For your reference, I have also attached the resultant PDF which is generated over my end.

[C#]

//Instantiate Pdf instance by calling
its empty constructor
<o:p></o:p>

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Create a list section

Aspose.Pdf.Generator.ListSection tocSection = new Aspose.Pdf.Generator.ListSection("Table Of Contents");

//Set its list type as table of of contents

tocSection.ListType = Aspose.Pdf.Generator.ListType.TableOfContents;

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

pdf1.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 = 10;

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

Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

//Add ten headings in the section

for (int Level = 1; Level != 11; Level++)

{

Aspose.Pdf.Generator.Heading heading2 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, Level);

Aspose.Pdf.Generator.Segment segment2 = new Aspose.Pdf.Generator.Segment(heading2);

heading2.Segments.Add(segment2);

heading2.IsAutoSequence = true;

segment2.Content = "this is heading of level ";

segment2.Content += Level.ToString();

//Add the heading into Table Of Contents.

heading2.IsInList = true;

sec1.Paragraphs.Add(heading2);

}

// save the PDF file

pdf1.Save("c:/pdftest/LargeTOC.pdf");