Aspose.Pdf

Apply Numbering Style

Headings are the important parts of any document. Writers always try to make headings more prominent and meaningful to its readers. If there are more than one headings in a document, a writer has several options to organize these headings. One of the most common approach to organize headings is to write headings in Numbering Style.

 

Aspose.Pdf offers many pre-defined numbering styles. These pre-defined numbering styles are stored in an enumeration, HeadingType . The pre-defined values of HeadingType enumeration and their descriptions are given below:

 

Heading Types

Description

Arab

Arab type,for example, 1,1.1,...

RomanUpper

Roman upper type, for example, I,I.II, ...

RomanLower

Roman lower type, for example, i,i.ii, ...

EnglishUpper

English upper type, for example, A,A.B, ...

EnglishLower

English lower type, for example, a,a.b, ...

 

The HeadingType property of Heading class is used to set the numbering styles of the headings.

The following figure shows the effect of different numbering styles:

 

 

Figure: Pre-defined numbering styles

 

The source code, to obtain the output shown in the above figure, is given below in the example.

 

Code Snippet

 

[C#]

 

//Instntiate the Pdf object by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Create the section in the Pdf object

Section sec1 = pdf1.Sections.Add();

 

/*

  * Create 1st heading in the Pdf object's section with level=1. Then create

  * a text segment and add it in the heading. Set its numbering style to "Arab"

  * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

  * If IsAutoSeguence property is set to true then the heading's sequence is

  * controlled automatically by Aspose.Pdf. After setting all properties, add

  * heading into the paragraphs collection of the section

  */

 

Heading heading1 = new Heading(pdf1,sec1,1);                       

Segment segment1 = new Segment(heading1);

heading1.Segments.Add(segment1);                       

segment1.Content = "Arab";                       

heading1.HeadingType=HeadingType.Arab;

heading1.IsAutoSequence=true;

sec1.Paragraphs.Add(heading1);

 

/*

  * Create 2nd heading in the Pdf object's section with level=1. Then create

  * a text segment and add it in the heading. Set its numbering style to "RomanUpper"

  * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

  * If IsAutoSeguence property is set to true then the heading's sequence is

  * controlled automatically by Aspose.Pdf. After setting all properties, add

  * heading into the paragraphs collection of the section

  */

 

Heading heading2 = new Heading(pdf1,sec1,1);

Segment segment2 = new Segment(heading2);

heading2.Segments.Add(segment2);                       

segment2.Content = "RomanUpper";

heading2.HeadingType=HeadingType.RomanUpper;

heading2.IsAutoSequence=true;

sec1.Paragraphs.Add(heading2);

 

/*

  * Create 3rd heading in the Pdf object's section with level=1. Then create

  * a text segment and add it in the heading. Set its numbering style to "RomanLower"

  * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

  * If IsAutoSeguence property is set to true then the heading's sequence is

  * controlled automatically by Aspose.Pdf. After setting all properties, add

  * heading into the paragraphs collection of the section

  */

 

Heading heading3 = new Heading(pdf1,sec1,1);

Segment segment3 = new Segment(heading3);

heading3.Segments.Add(segment3);                       

segment3.Content = "RomanLower";

heading3.HeadingType=HeadingType.RomanLower;

heading3.IsAutoSequence=true;

sec1.Paragraphs.Add(heading3);

 

/*

  * Create 4th heading in the Pdf object's section with level=1. Then create a

  * text segment and add it in the heading. Set its numbering style to "EnglishUpper"

  * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

  * If IsAutoSeguence property is set to true then the heading's sequence is

  * controlled automatically by Aspose.Pdf. After setting all properties, add

  * heading into the paragraphs collection of the section

  */

 

Heading heading4 = new Heading(pdf1,sec1,1);

Segment segment4 = new Segment(heading4);

heading4.Segments.Add(segment4);                       

segment4.Content = "RomanUpper";

heading4.HeadingType=HeadingType.EnglishUpper;

heading4.IsAutoSequence=true;

sec1.Paragraphs.Add(heading4);

 

/*

  * Create 5th heading in the Pdf object's section with level=1. Then create a

  * text segment and add it in the heading. Set its numbering style to "EnglishLower"

  * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

  * If IsAutoSeguence property is set to true then the heading's sequence is

  * controlled automatically by Aspose.Pdf. After setting all properties, add

  * heading into the paragraphs collection of the section

  */

 

Heading heading5 = new Heading(pdf1,sec1,1);

Segment segment5 = new Segment(heading5);

heading5.Segments.Add(segment5);                       

segment5.Content = "RomanLower";

heading5.HeadingType=HeadingType.EnglishLower;

heading5.IsAutoSequence=true;

sec1.Paragraphs.Add(heading5);

 

/*

  * Prepare HttpResponse object and save the Pdf to HttpResponse object to open in

  * Acrobat reader

  */

 

Response.ClearContent();

Response.ClearHeaders();

Response.ContentType="application/pdf";

pdf1.Save("headings.pdf",SaveType.OpenInAcrobat,Response);

Response.End();

 

[Visual Basic]

 

'Instntiate the Pdf object by calling its empty constructor

Dim pdf1 As Pdf =  New Pdf()

 

'Create the section in the Pdf object

Dim sec1 As Section =  pdf1.Sections.Add()

 

'*********************************************************************************

' * Create 1st heading in the Pdf object's section with level=1. Then create

' * a text segment and add it in the heading. Set its numbering style to "Arab"

' * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

' * If IsAutoSeguence property is set to true then the heading's sequence is

' * controlled automatically by Aspose.Pdf. After setting all properties, add

' * heading into the paragraphs collection of the section

'*********************************************************************************

 

Dim heading1 As Heading =  New Heading(pdf1,sec1,1) 

Dim segment1 As Segment =  New Segment(heading1)

heading1.Segments.Add(segment1)                       

segment1.Content = "Arab"                       

heading1.HeadingType=HeadingType.Arab

heading1.IsAutoSequence=True

sec1.Paragraphs.Add(heading1)

 

'*********************************************************************************

' * Create 2nd heading in the Pdf object's section with level=1. Then create a

' * text segment and add it in the heading. Set its numbering style to "RomanUpper"

' * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

' * If IsAutoSeguence property is set to true then the heading's sequence is

' * controlled automatically by Aspose.Pdf. After setting all properties, add

' * heading into the paragraphs collection of the section

'*********************************************************************************

 

Dim heading2 As Heading =  New Heading(pdf1,sec1,1)

Dim segment2 As Segment =  New Segment(heading2)

heading2.Segments.Add(segment2)                       

segment2.Content = "RomanUpper"

heading2.HeadingType=HeadingType.RomanUpper

heading2.IsAutoSequence=True

sec1.Paragraphs.Add(heading2)

 

'*********************************************************************************

' * Create 3rd heading in the Pdf object's section with level=1. Then create a

' * text segment and add it in the heading. Set its numbering style to "RomanLower"

' * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

' * If IsAutoSeguence property is set to true then the heading's sequence is

' * controlled automatically by Aspose.Pdf. After setting all properties, add

' * heading into the paragraphs collection of the section

'*********************************************************************************

 

Dim heading3 As Heading =  New Heading(pdf1,sec1,1)

Dim segment3 As Segment =  New Segment(heading3)

heading3.Segments.Add(segment3)                       

segment3.Content = "RomanLower"

heading3.HeadingType=HeadingType.RomanLower

heading3.IsAutoSequence=True

sec1.Paragraphs.Add(heading3)

 

'*********************************************************************************

' * Create 4th heading in the Pdf object's section with level=1. Then create a

' * text segment and add it in the heading. Set its numbering style to "EnglishUpper"

' * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

' * If IsAutoSeguence property is set to true then the heading's sequence is

' * controlled automatically by Aspose.Pdf. After setting all properties, add

' * heading into the paragraphs collection of the section

'*********************************************************************************

 

Dim heading4 As Heading =  New Heading(pdf1,sec1,1)

Dim segment4 As Segment =  New Segment(heading4)

heading4.Segments.Add(segment4)                       

segment4.Content = "RomanUpper"

heading4.HeadingType=HeadingType.EnglishUpper

heading4.IsAutoSequence=True

sec1.Paragraphs.Add(heading4)

 

'*********************************************************************************

' * Create 5th heading in the Pdf object's section with level=1. Then create a

' * text segment and add it in the heading. Set its numbering style to "EnglishLower"

' * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

' * If IsAutoSeguence property is set to true then the heading's sequence is

' * controlled automatically by Aspose.Pdf. After setting all properties, add

' * heading into the paragraphs collection of the section

'*********************************************************************************

 

Dim heading5 As Heading =  New Heading(pdf1,sec1,1)

Dim segment5 As Segment =  New Segment(heading5)

heading5.Segments.Add(segment5)                       

segment5.Content = "RomanLower"

heading5.HeadingType=HeadingType.EnglishLower

heading5.IsAutoSequence=True

sec1.Paragraphs.Add(heading5)

 

'*********************************************************************************

' * Prepare HttpResponse object and save the Pdf to HttpResponse object to open in

' * Acrobat reader

'*********************************************************************************

 

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType="application/pdf"

pdf1.Save("headings.pdf",SaveType.OpenInAcrobat,Response)

Response.End()

 

[JAVA]

 

//Instntiate the Pdf object by calling its empty constructor

Pdf pdf1 = new Pdf();

                                         

//Create the section in the Pdf object

Section sec1 = pdf1.getSections().add();

                                         

/*

* Create 1st heading in the Pdf object's section with level=1. Then create

* a text segment and add it in the heading. Set its numbering style to "Arab"

* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

* If IsAutoSeguence property is set to true then the heading's sequence is

* controlled automatically by Aspose.Pdf. After setting all properties, add

* heading into the paragraphs collection of the section

*/

                                         

Heading heading1 = new Heading(pdf1, sec1, 1);                       

Segment segment1 = new Segment(heading1, "Arab");

heading1.getSegments().add(segment1);

heading1.setHeadingType(HeadingType.Arab);

heading1.setIsAutoSequence(true);

sec1.getParagraphs().add(heading1);

 

/*

* Create 2nd heading in the Pdf object's section with level=2. Then create

* a text segment and add it in the heading. And don't forget to set

* IsAutoSequence=true.If IsAutoSeguence property is set to true then the

* heading's sequence is controlled automatically by Aspose.Pdf. After setting

* all properties, add heading into the paragraphs collection of the section

*/

Heading heading2 = new Heading(pdf1, sec1, 1);                       

Segment segment2 = new Segment(heading2, "RomanUpper");

heading2.getSegments().add(segment2);

heading2.setHeadingType(HeadingType.RomanUpper);

heading2.setIsAutoSequence(true);

sec1.getParagraphs().add(heading2);

 

/*

* Create 3rd heading in the Pdf object's section with level=1. Then create

* a text segment and add it in the heading. Set its numbering style to "RomanLower"

* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

* If IsAutoSeguence property is set to true then the heading's sequence is

* controlled automatically by Aspose.Pdf. After setting all properties, add

* heading into the paragraphs collection of the section

*/

Heading heading3 = new Heading(pdf1, sec1, 1);                       

Segment segment3 = new Segment(heading3, "RomanLower");

heading3.getSegments().add(segment3);

heading3.setHeadingType(HeadingType.RomanLower);

heading3.setIsAutoSequence(true);

sec1.getParagraphs().add(heading3);

 

/*

* Create 4th heading in the Pdf object's section with level=1. Then create a

* text segment and add it in the heading. Set its numbering style to "EnglishUpper"

* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

* If IsAutoSeguence property is set to true then the heading's sequence is

* controlled automatically by Aspose.Pdf. After setting all properties, add

* heading into the paragraphs collection of the section

*/

Heading heading4 = new Heading(pdf1, sec1, 1);                       

Segment segment4 = new Segment(heading4, "EnglishUpper");

heading4.getSegments().add(segment4);

heading4.setHeadingType(HeadingType.EnglishUpper);

heading4.setIsAutoSequence(true);

sec1.getParagraphs().add(heading4);

 

/*

* Create 5th heading in the Pdf object's section with level=1. Then create a

* text segment and add it in the heading. Set its numbering style to "EnglishLower"

* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.

* If IsAutoSeguence property is set to true then the heading's sequence is

* controlled automatically by Aspose.Pdf. After setting all properties, add

* heading into the paragraphs collection of the section

*/

Heading heading5 = new Heading(pdf1, sec1, 1);                       

Segment segment5 = new Segment(heading5, "EnglishLower");

heading5.getSegments().add(segment5);

heading5.setHeadingType(HeadingType.EnglishLower);

heading5.setIsAutoSequence(true);

sec1.getParagraphs().add(heading5);

 

[XML]

 

<?xml version="1.0" encoding="utf-8" ?>

  <Pdf xmlns="Aspose.Pdf">

   <Section>

            <Heading Level="1" HeadingType="Arab" IsAutoSequence="true">

                    <Segment>Arab</Segment>

            </Heading>

            <Heading Level="1" HeadingType="RomanUpper" IsAutoSequence="true">

                    <Segment>RomanUpper</Segment>

            </Heading>

            <Heading Level="1" HeadingType="RomanLower" IsAutoSequence="true">

                    <Segment>RomanLower</Segment>

            </Heading>

        <Heading Level="1" HeadingType="EnglishUpper" IsAutoSequence="true">

                    <Segment>EnglishUpper</Segment>

            </Heading>

            <Heading Level="1" HeadingType="EnglishLower" IsAutoSequence="true">

                    <Segment>EnglishLower</Segment>

            </Heading>

   </Section>

  </Pdf>