This example demonstrate how to draw bullets lists.
Our PDF library adds the ability to add unordered , unordered and sublist list to a pdf document:
BulletedList You can add bullet list in your pdf document.You can set a marker style, items can be added to list.sublist Any list can have child items or a sublist attached to it.
NumberedListYou can add a numbered or ordered list sublist Any list can have child items or a sublist attached to it.
After clicking the generate button will launch the pdf with preset list formats
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using OfficeComponent.Pdf;
using OfficeComponent.Pdf.Actions;
using OfficeComponent.Pdf.Annotations;
using OfficeComponent.Pdf.Forms;
using OfficeComponent.Pdf.Graphics;
using OfficeComponent.Pdf.Lists;
namespace OfficeComponent.Samples
{
class BulletsAndListsExample : ExampleBase
{
public BulletsAndListsExample(string commonDataPath, string outputDir)
: base(commonDataPath, outputDir)
{
}
public BulletsAndListsExample(string commonDataPath, string outputDir, string xmlFile) : base(commonDataPath, outputDir, xmlFile)
{
}
public override string Execute()
{
// Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
// Add a page
PdfPage page = document.Pages.Add();
PdfGraphics graphics = page.Graphics;
// Create a unordered list
PdfBulletedList list = new PdfBulletedList();
// Set the marker style
list.Marker.Style = PdfBulletedMarkerStyle.Disk;
// Create a font and write title
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);
graphics.DrawString("Bullets and Lists", font, PdfBrushes.DarkBlue, new PointF(225, 10));
string[] products = { "Red", "Green", "Blue" };
font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
graphics.DrawString("This sample demonstrates how to draw numbered list and bulleted list.", font, PdfBrushes.Black, new RectangleF(0, 50, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));
// Create string format
PdfStringFormat format = new PdfStringFormat();
format.LineSpacing = 20f;
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold);
// Apply formattings to list
list.Font = font;
list.StringFormat = format;
// Set list indent
list.Indent = 10;
//A dd items to the list
list.Items.Add("Colors");
list.Items.Add("Products");
// Set text indent
list.TextIndent = 10;
// Create Ordered list as sublist of parent list
PdfNumberedList subList = new PdfNumberedList();
subList.Marker.Brush = PdfBrushes.Black;
subList.Indent = 20;
list.Items[0].SubList = subList;
// Set format for sub list
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Italic);
subList.Font = font;
subList.StringFormat = format;
foreach (string s in products)
{
// Add items
subList.Items.Add(s);
}
// Create unorderd sublist for the second item of parent list
PdfBulletedList subsubList = new PdfBulletedList();
subsubList.Marker.Brush = PdfBrushes.Black;
subsubList.Indent = 20;
list.Items[1].SubList = subsubList;
PdfImage image = PdfImage.FromFile(CommonDataPath + "\\Logo.gif");
font = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Regular);
subsubList.Font = font;
subsubList.StringFormat = format;
// Add subitems
subsubList.Items.Add("OfficeComponent PDF");
subsubList.Items.Add("OfficeComponent FTP");
subsubList.Items.Add("OfficeComponent SFTP");
subsubList.Items.Add("OfficeComponent FTP Expert");
subsubList.Items.Add("OfficeComponent SSH Shell Telnet");
subsubList.Items.Add("OfficeComponent Mail");
subsubList.Items.Add("OfficeComponent Mail Expert");
subsubList.Items.Add("OfficeComponent Bounce Inspector");
subsubList.Items.Add("OfficeComponent Email Validator");
subsubList.Items.Add("OfficeComponent Template Engine");
subsubList.Items.Add("OfficeComponent Zip");
subsubList.Items.Add("OfficeComponent SAML");
subsubList.Items.Add("OfficeComponent Dns");
// Set image as marker
subsubList.Marker.Image = image;
// Draw list
list.Draw(page, new RectangleF(0, 130, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));
// Save and close the document.
var outputPath = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + ".pdf");
document.Save(outputPath);
document.Close(true);
return outputPath;
}
}
}
Imports System.IO
Imports System.Text
Imports OfficeComponent.Pdf
Imports OfficeComponent.Pdf.Actions
Imports OfficeComponent.Pdf.Annotations
Imports OfficeComponent.Pdf.Forms
Imports OfficeComponent.Pdf.Graphics
Imports OfficeComponent.Pdf.Lists
Namespace OfficeComponent.Samples
Friend Class BulletsAndListsExample
Inherits ExampleBase
Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String)
MyBase.New(commonDataPath, outputDir)
End Sub
Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String, ByVal xmlFile As String)
MyBase.New(commonDataPath, outputDir, xmlFile)
End Sub
Public Overrides Function Execute() As String
' Create a new instance of PdfDocument class.
Dim document As New PdfDocument()
' Add a page
Dim page As PdfPage = document.Pages.Add()
Dim graphics As PdfGraphics = page.Graphics
' Create a unordered list
Dim list As New PdfBulletedList()
' Set the marker style
list.Marker.Style = PdfBulletedMarkerStyle.Disk
' Create a font and write title
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold)
graphics.DrawString("Bullets and Lists", font, PdfBrushes.DarkBlue, New PointF(225, 10))
Dim products() As String = { "Red", "Green", "Blue" }
font = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
graphics.DrawString("This sample demonstrates how to draw numbered list and bulleted list.", font, PdfBrushes.Black, New RectangleF(0, 50, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height))
' Create string format
Dim format As New PdfStringFormat()
format.LineSpacing = 20F
font = New PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold)
' Apply formattings to list
list.Font = font
list.StringFormat = format
' Set list indent
list.Indent = 10
'A dd items to the list
list.Items.Add("Colors")
list.Items.Add("Products")
' Set text indent
list.TextIndent = 10
' Create Ordered list as sublist of parent list
Dim subList As New PdfNumberedList()
subList.Marker.Brush = PdfBrushes.Black
subList.Indent = 20
list.Items(0).SubList = subList
' Set format for sub list
font = New PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Italic)
subList.Font = font
subList.StringFormat = format
For Each s As String In products
' Add items
subList.Items.Add(s)
Next s
' Create unorderd sublist for the second item of parent list
Dim subsubList As New PdfBulletedList()
subsubList.Marker.Brush = PdfBrushes.Black
subsubList.Indent = 20
list.Items(1).SubList = subsubList
Dim image As PdfImage = PdfImage.FromFile(CommonDataPath & "\Logo.gif")
font = New PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Regular)
subsubList.Font = font
subsubList.StringFormat = format
' Add subitems
subsubList.Items.Add("OfficeComponent PDF")
subsubList.Items.Add("OfficeComponent FTP")
subsubList.Items.Add("OfficeComponent SFTP")
subsubList.Items.Add("OfficeComponent FTP Expert")
subsubList.Items.Add("OfficeComponent SSH Shell Telnet")
subsubList.Items.Add("OfficeComponent Mail")
subsubList.Items.Add("OfficeComponent Mail Expert")
subsubList.Items.Add("OfficeComponent Bounce Inspector")
subsubList.Items.Add("OfficeComponent Email Validator")
subsubList.Items.Add("OfficeComponent Template Engine")
subsubList.Items.Add("OfficeComponent Zip")
subsubList.Items.Add("OfficeComponent SAML")
subsubList.Items.Add("OfficeComponent Dns")
' Set image as marker
subsubList.Marker.Image = image
' Draw list
list.Draw(page, New RectangleF(0, 130, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height))
' Save and close the document.
Dim outputPath = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & ".pdf")
document.Save(outputPath)
document.Close(True)
Return outputPath
End Function
End Class
End Namespace