Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide number of sections and chapters in iTextSharp

Tags:

pdf

itextsharp

I need to hide the number of sections and chapters within the files that I generate with iTextSharp (within the content of the file, I do not care about bookmarks), for example I would need to change the actual result generated this way:

  1. This is Chapter Title 1

    1.1. This in section Title 1

by the following:

This is Chapter Title 1

This in section Title 1

I tried the following code, overriding the method OnSection:

public override void OnSection(PdfWriter writer, Document document, float paragraphPosition, int depth, Paragraph title)

    {title.RemoveAt(0);
        base.OnSection(writer, document, paragraphPosition, depth, title);
    }

But I did not get any results, could anyone help? Thank you very much, Ariel

like image 580
Ariel Serlin Avatar asked May 04 '11 16:05

Ariel Serlin


1 Answers

A chapter number has to be created using a Paragraph as title and an int as chapter number. The chapter number is shown by default. If you don't want to see the chapter number, you have to set the numberdepth to 0.

The same counts for section.

Sample:

Chapter chapter = new Chapter("ChapterTitle", 0);
chapter.NumberDepth = 0;

Section section = chapter.AddSection("Title", 0);
like image 183
Redlab Avatar answered Nov 12 '22 01:11

Redlab