How to Create List in PDF Document in C#, VB.NET

PDF list is a list to present each item with an order or specified format in PDF document. It can be the category which present each part of whole contents or just item list in one section. Actually, each item in list is a brief conclusion about the contents which it will introduce so that readers can learn more clearly about contents in a document with a list.

Spire.PDF for .NET, a stand-alone .NET component to generate, open and draw PDF document enables users to create list in PDF by using C#, VB.NET. Follow this guide, you can find how to create the list quickly via Spire.PDF for .NET.

Firstly, set location of this list and then confirm brush, font and contents of text in list. Secondly, declare a PDF list with contents which has been set in the first step. Then, set Font, Indent, TextIndent, Brush properties of this list. Thirdly, Draw list by using list.Draw(page, float x, float y) method. Now download and install Spire.PDF for .NET. Then, use the following code to create PDF list with C#, VB.NET.

Create Simple List

using System;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Lists;

namespace SimpleList
    class Program
        static void Main(string[] args)
            //Create PDF
            PdfDocument doc = new PdfDocument();

            //Add Page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4);
            float y = 10;

            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Impact", 18f, FontStyle.Regular), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Categories List", format1).Height;
            y = y + 5;

            //List Text and Text Format
            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush
                = new PdfLinearGradientBrush(rctg, Color.DarkBlue,Color.Brown, PdfLinearGradientMode.Vertical);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Tw Cen MT", 15f, FontStyle.Regular), true);
            String formatted
                = "Chap 1-Listening\nChap 2-Speaking\nChap 3-Reading\nChap 4-Writing"
                + "\nChap 5(Test 1)\nChap 6(Test 2)\nChap 7-Test Answers";

            //List Format
            PdfList list = new PdfList(formatted);
            list.Font = font2;
            list.Indent = 8;
            list.TextIndent = 5;
            list.Brush = brush;
            PdfLayoutResult result = list.Draw(page, 0, y);
            y = result.Bounds.Bottom;

            //Save and Launch File
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Lists

Namespace SimpleList
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Create PDF
            Dim doc As New PdfDocument()

            'Add Page
            Dim page As PdfPageBase = doc.Pages.Add(PdfPageSize.A4)

            Dim y As Single = 10

            Dim brush1 As PdfBrush = PdfBrushes.Black
            Dim font1 As New PdfTrueTypeFont(New Font("Impact", 18.0F, FontStyle.Regular), True)
            Dim format1 As New PdfStringFormat(PdfTextAlignment.Center)
            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width \ 2, y, format1)
            y = y + font1.MeasureString("Categories List", format1).Height
            y = y + 5

            'List Text and Text Format
            Dim rctg As New RectangleF(New PointF(0, 0), page.Canvas.ClientSize)
            Dim brush As New PdfLinearGradientBrush(rctg, Color.DarkBlue, Color.Brown, PdfLinearGradientMode.Vertical)
            Dim font2 As New PdfTrueTypeFont(New Font("Tw Cen MT", 15.0F, FontStyle.Regular), True)
            Dim formatted As String = "Chap 1-Listening" & vbLf & "Chap 2-Speaking" & vbLf & "Chap 3-Reading" & vbLf & "Chap 4-Writing" & vbLf & "Chap 5(Test 1)" & vbLf & "Chap 6(Test 2)" & vbLf & "Chap 7-Test Answers"

            'List Format
            Dim list As New PdfList(formatted)
            list.Font = font2
            list.Indent = 8
            list.TextIndent = 5
            list.Brush = brush
            Dim result As PdfLayoutResult = list.Draw(page, 0, y)
            y = result.Bounds.Bottom

            'Save and Launch File
        End Sub
    End Class
End Namespace

Spire.PDF for is a professional PDF component applied to create, read, write, edit and handle PDF documents without any external dependencies within .NET, WPF and Silverlight application.