Aspose.Pdf

Apply User Defined Bullets

We have already discussed in the previous topic that Aspose.Pdf provides 7 system defined bullets that can be used by developers. But Aspose.Pdf also offers the flexibility to add user defined bullets. It gives freedom to developers to use any desired symbol as a bullet.

 

To apply user defined bullet, set the BulletFontName property of Heading class to Symbol or ZapfDingbats (you can also use TrueType font such as Webdings). And then set the Heading.UserLabel property to the numeric value of the bullet symbol.

 

For example, UserLabel="44" and BulletFontName= "ZapfDingbats".

 

In the figure below, we have used three different bullet symbols with character values: 98, 99 and 100 while "Symbol" is used as BulletFontName .

 

User Defined Bullets

 

Figure: Demonstration of User defined bullets

 

The user defined bullets output in the above figure can be achieved using the source code 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 UserLabel="98" to use a user defined

  * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". 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 = "Symbol";

heading1.BulletFontName="Symbol";       

heading1.UserLabel="98";

sec1.Paragraphs.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. Set its UserLabel="99" to use a user defined

  * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting

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

  */

 

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

Segment segment2 = new Segment(heading2);

heading2.Segments.Add(segment2);                       

segment2.Content = "Symbol";

heading2.BulletFontName="Symbol";       

heading2.UserLabel="99";

sec1.Paragraphs.Add(heading2);

 

/*

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

  * segment and add it in the heading. Set its UserLabel="100" to use a user defined

  * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting

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

  */

 

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

Segment segment3 = new Segment(heading3);

heading3.Segments.Add(segment3);                       

segment3.Content = "Symbol";

heading3.BulletFontName="Symbol";       

heading3.UserLabel="100";

sec1.Paragraphs.Add(heading3);                       

 

/*

  * 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();

 

[VB.NET]

 

'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 UserLabel="98" to use a user defined

' * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". 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 = "Symbol"

heading1.BulletFontName="Symbol"       

heading1.UserLabel="98"

sec1.Paragraphs.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. Set its UserLabel="99" to use a user defined

' * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting

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

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

 

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

Dim segment2 As Segment =  New Segment(heading2)

heading2.Segments.Add(segment2)                       

segment2.Content = "Symbol"

heading2.BulletFontName="Symbol"       

heading2.UserLabel="99"

sec1.Paragraphs.Add(heading2)

 

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

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

' * segment and add it in the heading. Set its UserLabel="100" to use a user defined

' * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting

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

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

 

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

Dim segment3 As Segment =  New Segment(heading3)

heading3.Segments.Add(segment3)                       

segment3.Content = "Symbol"

heading3.BulletFontName="Symbol"       

heading3.UserLabel="100"

sec1.Paragraphs.Add(heading3)                       

 

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

' * 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 UserLabel="98" to use a user defined

* bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". 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.getSegments().add(segment1);

segment1.setContent("Symbol");

heading1.setBulletFontName("Symbol");                                                                                   

heading1.setUserLabel("98");

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. Set its UserLabel="99" to use a user defined

* bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting

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

*/                           

 

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

Segment segment2 = new Segment(heading2);

heading2.getSegments().add(segment2);

segment2.setContent("Symbol");

heading2.setBulletFontName("Symbol") ;

heading2.setUserLabel("99");

sec1.getParagraphs().add(heading2);

                                         

/*

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

* segment and add it in the heading. Set its UserLabel="100" to use a user defined

* bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting

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

*/                           

 

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

Segment segment3 = new Segment(heading3);

heading3.getSegments().add(segment3);         

segment3.setContent("Symbol");

heading3.setBulletFontName("Symbol") ;    

heading3.setUserLabel("100");

sec1.getParagraphs().add(heading3);           

 

[XML]

 

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

  <Pdf xmlns="Aspose.Pdf">

   <Section>

            <Heading Level="1" UserLabel="98" BulletFontName="Symbol">

                    <Segment>Symbol</Segment>

            </Heading>

            <Heading Level="2" UserLabel="99" BulletFontName="Symbol">

                    <Segment>Symbol</Segment>

            </Heading>

            <Heading Level="3" UserLabel="100" BulletFontName="Symbol">

                    <Segment>Symbol</Segment>

            </Heading>       

   </Section>

  </Pdf>