C# 创建Word项目标号列表、多级编号列表

作者:编程技术

行使项指标识和编号,可以让文书档案的档次构造更清晰、更有系统,也更便于优越器重。在编辑文档的历程中,作者个人也比较偏疼项指标号来说明作品主要音信。在事前的小说中,介绍了什么样在Word中来创立项目的号和编号列表,在本篇小说中,将介绍成立PDF项目的志列表和多元编号列表的措施。

行使工具Free Spire.Doc for .NET(社区版)

 

依傍工具: Spire.PDF.dll

应用方法:在设置该类库后,在档案的次序中援用Spire.Doc.dll就能够(dll文件可在设置路线下的Bin文件夹中收获卡塔尔

应用工具:Free Spire.PDF for .NET

PS:dll能够直接在设置路线下的Bin文件夹中获取。

黄金时代、创立项指标号列表

using Spire.Doc;
using Spire.Doc.Documents;

namespace WordBullets
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化Document类实例,并添加section
            Document doc = new Document();
            Section section = doc.AddSection();

            //添加七个段落并分别添加文字
            Paragraph para1 = section.AddParagraph();
            para1.AppendText("国际政治类组织");
            Paragraph para2 = section.AddParagraph();
            para2.AppendText("欧洲联盟(欧盟)");
            Paragraph para3 = section.AddParagraph();
            para3.AppendText("独立国家联合体(独联体)");
            Paragraph para4 = section.AddParagraph();
            para4.AppendText("上海合作组织");
            Paragraph para5 = section.AddParagraph();
            para5.AppendText("阿拉伯会议联盟");
            Paragraph para6 = section.AddParagraph();
            para6.AppendText("国际生态安全合作组织");
            Paragraph para7 = section.AddParagraph();
            para7.AppendText("阿拉伯国家联盟");

            //创建段落格式(字体)
            ParagraphStyle style = new ParagraphStyle(doc);
            style.Name = "fontStyle";
            style.CharacterFormat.FontName = "宋体";
            style.CharacterFormat.FontSize = 12f;
            doc.Styles.Add(style);

            //遍历所有段落
            for (int i = 0; i < section.Paragraphs.Count; i  )
            {
                //从第二段开始应用项目符号排列
                if (i != 0)
                {
                    section.Paragraphs[i].ApplyStyle(BuiltinStyle.ListBullet2);
                }

                //应用字体格式到每一段
                section.Paragraphs[i].ApplyStyle("fontStyle");

            }
            //保存并打开文档
            doc.SaveToFile("项目列表.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("项目列表.docx");
        }
    }
}

测量检验效果:

图片 1

谢谢阅读!

2.创办PDF多级编号列表

Spire.Pdf.dll扶植三体系型的号子类型:

图片 2

C#

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

namespace List2
{
    class Program
    {
        static void Main(string[] args)
        {
            //新建PDF文档,并添加一页A4大小的空白页面
            PdfDocument doc = new PdfDocument();
            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("目录一览", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y   font1.MeasureString("目录一览", format1).Height;
            y = y   5;

            //添加文本并设置字体
            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("宋体", 15f, FontStyle.Regular), true);
            String formatted1 = "第一章 总 论";
            String formatted2 = "第一节 经济法概述 ";
            String formatted3 = "第二节 经济法主体 ";
            String formatted4 = "第二章 公司法律制度";

            //设置编号列表样式
            PdfOrderedMarker marker1 = new PdfOrderedMarker(PdfNumberStyle.Numeric, new PdfFont(PdfFontFamily.Helvetica, 15f));
            PdfOrderedMarker marker2 = new PdfOrderedMarker(PdfNumberStyle.LowerRoman, new PdfFont(PdfFontFamily.Helvetica, 12f));

            //为第一级编号列表设置格式
            PdfSortedList list1 = new PdfSortedList(font2);
            list1.Indent = 0;
            list1.TextIndent = 5;
            list1.Brush = brush;
            list1.Marker = marker1;

            //为第二级编号列表设置格式
            PdfSortedList list2 = new PdfSortedList(font2);
            list2.Marker = marker2;
            list2.Brush = brush;
            list2.TextIndent = 10;

            //应用编号列表格式到指定文本
            PdfListItem item = list1.Items.Add(formatted1);
            item.SubList = list2;
            list2.Items.Add(formatted2);
            list2.Items.Add(formatted3);
            list1.Items.Add(formatted4);            

            //设置PDF文档布局和位置
            PdfTextLayout textLayout = new PdfTextLayout();
            textLayout.Break = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            list1.Draw(page, new PointF(0, y), textLayout);

            //保存文件
            doc.SaveToFile("多级列表.pdf");
            System.Diagnostics.Process.Start("多级列表.pdf");
        }
    }
}

测量检验结果:

图片 3

VB.NET

Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Lists
Imports System
Imports System.Drawing

Namespace List2

    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("目录一览", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1)
            y = y   font1.MeasureString("目录一览", 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.DarkBlue, Color.Brown, PdfLinearGradientMode.Vertical)
            Dim font2 As PdfTrueTypeFont = New PdfTrueTypeFont(New Font("宋体", 15F, FontStyle.Regular), True)
            Dim formatted1 As String = "第一章 总 论"
            Dim formatted2 As String = "第一节 经济法概述 "
            Dim formatted3 As String = "第二节 经济法主体 "
            Dim formatted4 As String = "第二章 公司法律制度"
            Dim marker1 As PdfOrderedMarker = New PdfOrderedMarker(PdfNumberStyle.Numeric, NewPdfFont(PdfFontFamily.Helvetica, 15F))
            Dim marker2 As PdfOrderedMarker = New PdfOrderedMarker(PdfNumberStyle.LowerRoman, NewPdfFont(PdfFontFamily.Helvetica, 12F))
            Dim list1 As PdfSortedList = New PdfSortedList(font2)
            list1.Indent = 0
            list1.TextIndent = 5
            list1.Brush = brush
            list1.Marker = marker1
            Dim list2 As PdfSortedList = New PdfSortedList(font2)
            list2.Marker = marker2
            list2.Brush = brush
            list2.TextIndent = 10
            Dim item As PdfListItem = list1.Items.Add(formatted1)
            item.SubList = list2
            list2.Items.Add(formatted2)
            list2.Items.Add(formatted3)
            list1.Items.Add(formatted4)
            Dim textLayout As PdfTextLayout = New PdfTextLayout()
            textLayout.Break = PdfLayoutBreakType.FitPage
            textLayout.Layout = PdfLayoutType.Paginate
            list1.Draw(page, New PointF(0, y), textLayout)
            doc.SaveToFile("多级列表.pdf")
            System.Diagnostics.Process.Start("多级列表.pdf")
        End Sub
    End Class
End Namespace

上述内容为本次关于“创立PDF项目的号列表和文山会海编号列表”的全体内容。如需转发,请注解出处。多谢阅读!

 

在Word文档中,对于有多条并列的新闻内容或然段落时,大家常以增添项指标号的情势来使文书档案条理化,在阅读时,文档也更具雅观性。其余,对于在逻辑上存在必然层级布局的剧情时,也足以经过类别编号列表来注解文书档案内容的档期的顺序,而且,在更改、编辑文书档案时也增添了灵活性。因而,在本篇文书档案中,将介绍如何在C#中经过行使类库Free Spire.Doc for .NET 来创设项目编号列表和二种编号列表的方法。

图片 4

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");
        }
    }
}

测验结果:

图片 5

 

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

二、创设多级编号列表

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace Multi_levelList_Doc
{
    class Program
    {
        static void Main(string[] args)
        {
            //新建Word文档
            Document doc = new Document();
            Section section = doc.AddSection();

            //初始化ListStyle对象,指定List类型为数字列表并命名
            ListStyle listStyle = new ListStyle(doc, ListType.Numbered);
            listStyle.Name = "levelstyle";

            //设定一级列表模式为阿拉伯数字
            listStyle.Levels[0].PatternType = ListPatternType.Arabic;

            //设置二级列表数字前缀及模式
            listStyle.Levels[1].NumberPrefix = "x0000.";
            listStyle.Levels[1].PatternType = ListPatternType.Arabic;

            //设置三级列表数字前缀及模式
            listStyle.Levels[2].NumberPrefix = "x0000.x0001.";
            listStyle.Levels[2].PatternType = ListPatternType.Arabic;

            //在ListStyles集合中添加新建的list style
            doc.ListStyles.Add(listStyle);

            //创建字体格式
            Spire.Doc.Formatting.CharacterFormat format = new Spire.Doc.Formatting.CharacterFormat(doc);
            format.FontName = "宋体";

            //添加段落,设置一级序列
            Paragraph paragraph = section.AddParagraph();
            TextRange tr = paragraph.AppendText("主要组织机构");
            tr.ApplyCharacterFormat(format); //应用字体格式
            paragraph.ApplyStyle(BuiltinStyle.Heading1); //应用标题1样式
            paragraph.ListFormat.ApplyStyle("levelstyle"); //应用列表样式

            //添加段落,设置一级序列
            paragraph = section.AddParagraph();
            tr = paragraph.AppendText("主要职能");
            tr.ApplyCharacterFormat(format);
            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            paragraph.ListFormat.ApplyStyle("levelstyle");

            //添加段落,设置二级序列
            paragraph = section.AddParagraph();
            tr = paragraph.AppendText("基本职能");
            tr.ApplyCharacterFormat(format);
            paragraph.ApplyStyle(BuiltinStyle.Heading2);
            paragraph.ListFormat.ListLevelNumber = 1; //设置等级为第二等级
            paragraph.ListFormat.ApplyStyle("levelstyle");

            //添加段落,设置二级序列
            paragraph = section.AddParagraph();
            tr = paragraph.AppendText("5大职能");
            tr.ApplyCharacterFormat(format);
            paragraph.ApplyStyle(BuiltinStyle.Heading2);
            paragraph.ListFormat.ContinueListNumbering();
            paragraph.ListFormat.ApplyStyle("levelstyle");

            //添加段落,设置三级序列
            paragraph = section.AddParagraph();
            tr = paragraph.AppendText("管理职能 n 组织职能 n 协调职能 n 调节职能 n 提供职能");
            tr.ApplyCharacterFormat(format);
            paragraph.ApplyStyle(BuiltinStyle.Heading5);
            paragraph.ListFormat.ListLevelNumber = 2; //设置等级为第三等级
            paragraph.ListFormat.ApplyStyle("levelstyle");

            //添加段落,设置一级序列
            paragraph = section.AddParagraph();
            tr = paragraph.AppendText("基本原则");
            tr.ApplyCharacterFormat(format);
            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            paragraph.ListFormat.ApplyStyle("levelstyle");

            //保存并打开文档
            doc.SaveToFile("多级列表.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("多级列表.docx");
        }
    }
}

测量试验效果:

图片 6

以上代码供参谋,招待转发(转发请注解出处卡塔尔。

多谢阅读! 

 全部代码

PS: 本篇小说是对Free Spire.PDF 的联合成效的愈发介绍,即什么联合三个PDF文书档案中的钦点页(钦定单页、钦赐多页卡塔 尔(英语:State of Qatar)为三个新文档,越来越多关于Free Spire.PDF对PDF文书档案的操作功能可参看这里的博客。

图片 7

以上内容是本次关于“怎么着联合PDF文书档案钦点页”的整套介绍,假使中意,应接转发(转发请证明出处卡塔 尔(英语:State of Qatar)

 

合并前:

合并后:

Imports Spire.Pdf
Imports System.Diagnostics

Namespace MergeSelectedPDFpages

    Class Program

        Private Shared Sub Main(ByVal args() As String)
            Dim files() As String = New String() {"sample1.pdf", "sample2.pdf"}
            Dim docs() As PdfDocument = New PdfDocument((files.Length) - 1) {}
            Dim i As Integer = 0
            Do While (i < files.Length)
                docs(i) = New PdfDocument
                docs(i).LoadFromFile(files(i))
                i = (i   1)
            Loop

            Dim doc As PdfDocument = New PdfDocument
            doc.InsertPage(docs(0), 0)
            doc.InsertPageRange(docs(1), 0, 1)
            doc.SaveToFile("Result.pdf")
            Process.Start("Result.pdf")
        End Sub
    End Class
End Namespace
using Spire.Pdf;
using System.Diagnostics;

namespace MergeSelectedPDFpages
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] files = { "sample1.pdf", "sample2.pdf" };
            PdfDocument[] docs = new PdfDocument[files.Length];

            for (int i = 0; i < files.Length; i  )
            {
               docs[i] = new PdfDocument();
               docs[i].LoadFromFile(files[i]);
            }

            PdfDocument doc = new PdfDocument();
            doc.InsertPage(docs[0], 0); 
            doc.InsertPageRange(docs[1], 0, 1);     

            doc.SaveToFile("Result.pdf");
            Process.Start("Result.pdf");
        }
    }
}

提示下载安装该器件后,注意在类型前后相继中丰裕援用Spire.PDF.dll文件

在前边的篇章中,大家已经精通哪些统后生可畏、拆分七个PDF文件,在此篇随笔中的合併、拆分PDF文档主倘使以利于文书档案管理的指标来操作文书档案,在文书档案查阅、管理及积攒上很便利实用。然则大家假如想要合并四个文书档案中的部分文书档案页的内容,该怎么来做吗?能够参照接下去将在介绍的联结方法。

代码细节可参看以下重视代码段:

           //初始化数组,数组元素为需要合并的PDF文档
            string[] files = { "sample1.pdf", "sample2.pdf" };
            PdfDocument[] docs = new PdfDocument[files.Length];
            //遍历PDF文档
            for (int i = 0; i < files.Length; i  )
            {
                docs[i] = new PdfDocument();
                docs[i].LoadFromFile(files[i]);
            }
            //创建一个新的PDF文档并插入从原文档选取的指定页
            PdfDocument doc = new PdfDocument();
            doc.InsertPage(docs[0], 0);//指定单页
            doc.InsertPageRange(docs[1], 0, 1);//指定多页      

            //保存并命名合并后的文档,同时运行文档
            doc.SaveToFile("Result.pdf");
            Process.Start("Result.pdf");

VB.NET

C#

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划