Free Support Forum - aspose.com

How to remove last paragraphe break

Hi,

I create my TOC dynamically and when it goes at the bottom of the page, it creates a empty page after my TOC (there’s a break page between my TOC and the next page).


Manually I can erase the last paragraphe break, but I can’t find how I can do it programmatically.

Here’s the code.

Document docIntro = new Document(path);

DocumentBuilder docBuilder = new DocumentBuilder(docIntro);
docBuilder.MoveToBookmark(“toc”);
docBuilder = CreateToc(docBuilder);

private DocumentBuilder CreateToc(DocumentBuilder docBuilder
{
intPageNumber = 1;

// Aspose Code
for (int i = 0; i < SelectedFiles.Count; i++)
{

MyClassFile file = GetMyClassFileById(myId);
Document newFile = new Document(file.Path);

// When is a new category, I use Heading 3 format
if (isHeading3)
{
docBuilder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.Heading3;
docBuilder.Writeln(file.Category.Name);
docBuilder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
}

docBuilder.Writeln(file.Name + " \t" + intPageNumber);
intPageNumber++;

}
// Here I think I should remove the last paragraph page
}

I sent 2 docs:
Intro_toc.doc: My intro doc with an empty TOC
toc.doc: A document with a TOC example

Thanks alot



Hi

Thanks for your inquiry. I think that you can try using the following code snippet.

for (int i = 0; i < count; i++)

{

if (i < count - 1)

{

docBuilder.Writeln("test" + " \t" + intPageNumber);

}

else

{

docBuilder.Write("test" + " \t" + intPageNumber);

}

intPageNumber++;

}

Best regards.