标签:
使用项目标记和编号,可以让文档的条理布局更清晰、更有层次,也更容易突出重点。在编纂文档的过程中,,我小我私家也对照偏爱项方针号来标注文章重点信息。在之前的文章中,介绍了如安在Word中来创建项方针号和编号列表,在本篇文章中,将介绍创建PDF项目标记列表和多级编号列表的要领。借助工具:Free Spire.PDF for .NET
PS:dll可以直接在安置路径下的Bin文件夹中获取。 1.创建PDF标记列表 C using System; using System.Drawing; using Spire.Pdf; using Spire.Pdf.Graphics; using Spire.Pdf.Lists; namespace CreateList_PDF { class Program { static void Main(string[] args) { //创建一个PDF文档 PdfDocument doc = new PdfDocument(); //添加一页A4巨细的页面 PdfPageBase page = doc.Pages.Add(PdfPageSize.A4); float y = 10; //创建标题并设置格局,包孕字体、字号、颜色 PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("楷体", 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; //创建列表文字并设置格局 RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize); PdfLinearGradientBrush brush = new PdfLinearGradientBrush(rctg, Color.SteelBlue, Color.Blue, PdfLinearGradientMode.Vertical); PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("宋体", 15f, FontStyle.Regular), true); String formatted = "Part 1 Listening(听力部分) \n Part 2 Speaking(白话部分) \n Part 3 Reading(阅读部分) \n Part 4 Writing(写作部分)" + "\n Part 5 Test(测试) 1 \n Part 6 Test(测试) 2 \n Part 7 Test Answers(测试答案)"; //创建PdfList 类东西,并设置列表及样式 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; //生存并打开文档 doc.SaveToFile("List.pdf"); System.Diagnostics.Process.Start("List.pdf"); } } }
测试功效:
VB.NET Imports System Imports System.Drawing Imports Spire.Pdf Imports Spire.Pdf.Graphics Imports Spire.Pdf.Lists Namespace CreateList_PDF Class Program Private Shared Sub Main(ByVal args As String()) Dim doc As PdfDocument = New PdfDocument() Dim page As PdfPageBase = doc.Pages.Add(PdfPageSize.A4) Dim y As Single = 10 Dim brush1 As PdfBrush = PdfBrushes.Black Dim font1 As PdfTrueTypeFont = New PdfTrueTypeFont(New Font("楷体", 18F, FontStyle.Regular), True) Dim format1 As PdfStringFormat = 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 Dim rctg As RectangleF = New RectangleF(New PointF(0, 0), page.Canvas.ClientSize) Dim brush As PdfLinearGradientBrush = New PdfLinearGradientBrush(rctg, Color.SteelBlue, Color.Blue, PdfLinearGradientMode.Vertical) Dim font2 As PdfTrueTypeFont = New PdfTrueTypeFont(New Font("宋体", 15F, FontStyle.Regular), True) Dim formatted As String = "Part 1 Listening(听力部分) " & vbLf & " Part 2 Speaking(白话部分) " & vbLf & " Part 3 Reading(阅读部分) " & vbLf & " Part 4 Writing(写作部分)" & vbLf & " Part 5 Test(测试) 1 " & vbLf & " Part 6 Test(测试) 2 " & vbLf & " Part 7 Test Answers(测试答案)" Dim list As PdfList = 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 doc.SaveToFile("List.pdf") System.Diagnostics.Process.Start("List.pdf") End Sub End Class End Namespace 2.创建PDF多级编号列表Spire.Pdf.dll撑持多种类型的编号类型