基本造型,怎样插入图片

透过对控件Spire.PDF的测试,大家得以创建PDF文件并向文书档案中绘制文本、图片、表格、图形等内容,当中,对于绘制文本那1部分,Spire.PDF提供了两种字体类型来绘制文本,即:

一、序言

在Office
Word中,匡助在Word文书档案中插入类型格外丰硕的形象,包涵线条、矩形、基本造型(诸如圆形、多边形、星形、括号、笑脸等等图形)、箭头形状、公式形状、流程图、旗帜图形、标注图形等等,大家在编制程序进程中,想要在Word中绘制差别品类的图片,能够透过类库来操作。控件Spire.Doc
for .NET 6.0及以上版本初始帮助Office
Word中的全体图形,能够通过代码操作有些单壹的造型,也能够透过将单纯形状进行整合来收获想要的图纸或形状效果,当然,也扶助本人自定义图形,通过编制程序绘制也是足以的。下边将介绍向Word绘制形状和组成造型的法子,方法中的代码供参考。

PS:

  • Spire.Doc for
    .NET
    获得地址
  • 设置后,dll文件可在设置路径下的Bin文件夹中拿走

Dll引用

亚洲必赢官网 1

对文书档案添加水印能够有效表明和护卫文书档案,是爱戴主要文件的艺术之一。在PPT文档中同样也得以安装水印,包涵文件水印和图表水印,本文将讲述怎么样通过Spire.Presentation
for .NET来对PPT添加水印,下载安装Free Spire.Presentationfor
.NET后,添加引用dll文件,参考上边包车型大巴操作步骤,完毕水印添加。

在最近的稿子C#
怎样插入、修改、删除Word批注一文中牵线了什么操作Word批注的一对主意,在本篇小说中再三再四介绍操作Word批注的主意。分以下两种状态来介绍:

  1. 插入图片到Word批注

  2. 读取Word批注

  3. 回复Word批注

  • Standard fonts
  • 基本造型,怎样插入图片。TrueType fonts
  • Chinese, Japanese and Korean (CJK) fonts

二、代码示例

一.添加文书水印

所需工具

  • Free Spire.Doc for .NET
    6.3(社区版)
  • Visual Studio

 PS:下载安装Free Spire.Doc
后,注意在您的顺序中添加引用Spire.Doc.dll(dll文件能够在装置路径下的Bin文件夹中收获)

亚洲必赢官网 2

 

从上述类中大家得以窥见,是能够辅助中、日、韩、英等字体类的,那为大家在操作PDF文件上提供了更加多只怕。在那篇小说中,“选用private
font改变PDF文件的字体”中讲述了如何使用字体,在接下去的篇章中,将介绍怎么着利用Spire.PDF提供的书体类来绘制分歧风格类型的文书。

(一)绘制单1形状

步骤1:添加如下using钦赐

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

 

步骤二:创造示范,添加section、paragraph

//创建一个Document实例
Document doc = new Document();
//添加一个section paragraph
 Section sec = doc.AddSection();
 Paragraph para1 = sec.AddParagraph();

 

手续三:在文书档案内定地点插入形状,并安装形状类型、大小、填充颜色、线条样式等

(那里大致列举多少个造型的丰裕方法,方法相比不难,不做赘述,效果图中列举了部分形象样式,需求其它样式的造型可自动安装添加)

           //插入一个矩形
            ShapeObject shape1 = para1.AppendShape(50, 50, ShapeType.Rectangle);
            shape1.FillColor = Color.Blue;
            shape1.StrokeColor = Color.LightSkyBlue;
            shape1.HorizontalPosition = 20;
            shape1.VerticalPosition = 20;

            //插入一个圆形
            ShapeObject shape2 = para1.AppendShape(50, 50, ShapeType.Ellipse);
            shape2.FillColor = Color.Purple;
            shape2.StrokeColor = Color.LightPink;
            shape2.LineStyle = ShapeLineStyle.Single;
            shape2.StrokeWeight = 1;
            shape2.HorizontalPosition = 80;
            shape2.VerticalPosition = 20;

            //插入一个公式符号 +
            ShapeObject shape3 = para1.AppendShape(50, 50, ShapeType.Plus);
            shape3.FillColor = Color.DarkCyan;
            shape3.StrokeColor = Color.LightGreen;
            shape3.LineStyle = ShapeLineStyle.Single;
            shape3.StrokeWeight = 1;
            shape3.HorizontalPosition = 140;
            shape3.VerticalPosition = 20;

            //插入一颗星形
            ShapeObject shape4 = para1.AppendShape(50, 50, ShapeType.Star);
            shape4.FillColor = Color.Red;
            shape4.StrokeColor = Color.Gold;
            shape4.LineStyle = ShapeLineStyle.Single;
            shape4.HorizontalPosition = 200;
            shape4.VerticalPosition = 20;

 

手续四:保存文书档案

//保存并打开文档
doc.SaveToFile("InsertShapes.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("InsertShapes.docx");

 

形态添加效果:

亚洲必赢官网 3

成套代码:

亚洲必赢官网 4亚洲必赢官网 5

  1 using Spire.Doc;
  2 using Spire.Doc.Documents;
  3 using Spire.Doc.Fields;
  4 using System.Drawing;
  5 
  6 namespace AddShapes_Doc
  7 {
  8     class Program
  9     {
 10         static void Main(string[] args)
 11         {
 12             //创建一个Document实例
 13             Document doc = new Document();
 14 
 15             //添加一个section paragraph
 16             Section sec = doc.AddSection();
 17             Paragraph para1 = sec.AddParagraph();
 18 
 19             //插入一个矩形
 20             ShapeObject shape1 = para1.AppendShape(50, 50, ShapeType.Rectangle);
 21             shape1.FillColor = Color.Blue;
 22             shape1.StrokeColor = Color.LightSkyBlue;
 23             shape1.HorizontalPosition = 20;
 24             shape1.VerticalPosition = 20;
 25 
 26             //插入一个圆形
 27             ShapeObject shape2 = para1.AppendShape(50, 50, ShapeType.Ellipse);
 28             shape2.FillColor = Color.Purple;
 29             shape2.StrokeColor = Color.LightPink;
 30             shape2.LineStyle = ShapeLineStyle.Single;
 31             shape2.StrokeWeight = 1;
 32             shape2.HorizontalPosition = 80;
 33             shape2.VerticalPosition = 20;
 34 
 35             //插入一个公式符号 +
 36             ShapeObject shape3 = para1.AppendShape(50, 50, ShapeType.Plus);
 37             shape3.FillColor = Color.DarkCyan;
 38             shape3.StrokeColor = Color.LightGreen;
 39             shape3.LineStyle = ShapeLineStyle.Single;
 40             shape3.StrokeWeight = 1;
 41             shape3.HorizontalPosition = 140;
 42             shape3.VerticalPosition = 20;
 43 
 44             //插入一颗星形
 45             ShapeObject shape4 = para1.AppendShape(50, 50, ShapeType.Star);
 46             shape4.FillColor = Color.Red;
 47             shape4.StrokeColor = Color.Gold;
 48             shape4.LineStyle = ShapeLineStyle.Single;
 49             shape4.HorizontalPosition = 200;
 50             shape4.VerticalPosition = 20;
 51 
 52             //插入一个立方体
 53             ShapeObject shape5 = para1.AppendShape(50, 50, ShapeType.Cube);
 54             shape5.FillColor = Color.OrangeRed;
 55             shape5.StrokeColor = Color.Orange;
 56             shape5.LineStyle = ShapeLineStyle.Single;
 57             shape5.HorizontalPosition = 260;
 58             shape5.VerticalPosition = 20;
 59 
 60             //插入一个圆柱体
 61             ShapeObject shape6 = para1.AppendShape(50, 50, ShapeType.Can);
 62             shape6.FillColor = Color.Goldenrod;
 63             shape6.StrokeColor = Color.Gold;
 64             shape6.LineStyle = ShapeLineStyle.Single;
 65             shape6.HorizontalPosition = 320;
 66             shape6.VerticalPosition = 20;
 67 
 68             //插入一个箭头
 69             ShapeObject shape7 = para1.AppendShape(50, 50, ShapeType.Arrow);
 70             shape7.FillColor = Color.Yellow;
 71             shape7.StrokeColor = Color.Yellow;
 72             shape7.LineStyle = ShapeLineStyle.Single;
 73             shape7.HorizontalPosition = 20;
 74             shape7.VerticalPosition = 80;
 75 
 76             //插入一个v形臂章图形
 77             ShapeObject shape8 = para1.AppendShape(50, 50, ShapeType.Chevron);
 78             shape8.FillColor = Color.YellowGreen;
 79             shape8.StrokeColor = Color.Yellow;
 80             shape8.LineStyle = ShapeLineStyle.Single;
 81             shape8.HorizontalPosition = 80;
 82             shape8.VerticalPosition = 80;
 83 
 84             //插入一个循环箭头图形
 85             ShapeObject shape9 = para1.AppendShape(50, 50, ShapeType.CircularArrow);
 86             shape9.FillColor = Color.Green;
 87             shape9.StrokeColor = Color.Yellow;
 88             shape9.LineStyle = ShapeLineStyle.Single;
 89             shape9.HorizontalPosition = 140;
 90             shape9.VerticalPosition = 80;
 91 
 92             //插入一个云图形
 93             ShapeObject shape10 = para1.AppendShape(50, 50, ShapeType.CloudCallout);
 94             shape10.FillColor = Color.LightSkyBlue;
 95             shape10.StrokeColor = Color.White;
 96             shape10.LineStyle = ShapeLineStyle.Single;
 97             shape10.HorizontalPosition = 200;
 98             shape10.VerticalPosition = 80;
 99 
100             //插入一个环形图
101             ShapeObject shape11 = para1.AppendShape(50, 50, ShapeType.Donut);
102             shape11.FillColor = Color.Pink;
103             shape11.StrokeColor = Color.White;
104             shape11.LineStyle = ShapeLineStyle.Single;
105             shape11.HorizontalPosition = 260;
106             shape11.VerticalPosition = 80;
107 
108             //插入一个波浪形状图
109             ShapeObject shape12 = para1.AppendShape(50, 50, ShapeType.DoubleWave);
110             shape12.FillColor = Color.Plum;
111             shape12.StrokeColor = Color.White;
112             shape12.LineStyle = ShapeLineStyle.Single;
113             shape12.HorizontalPosition = 320;
114             shape12.VerticalPosition = 80;
115 
116             //插入一个礼结状图形
117             ShapeObject shape13 = para1.AppendShape(50, 50, ShapeType.EllipseRibbon);
118             shape13.FillColor = Color.RosyBrown;
119             shape13.StrokeColor = Color.White;
120             shape13.LineStyle = ShapeLineStyle.Single;
121             shape13.HorizontalPosition = 20;
122             shape13.VerticalPosition = 140;
123 
124             //插入一个心形图
125             ShapeObject shape14 = para1.AppendShape(50, 50, ShapeType.Heart);
126             shape14.FillColor = Color.Red;
127             shape14.StrokeColor = Color.White;
128             shape14.LineStyle = ShapeLineStyle.Single;
129             shape14.HorizontalPosition = 80;
130             shape14.VerticalPosition = 140;
131 
132             //插入一个六边形图形
133             ShapeObject shape15 = para1.AppendShape(50, 50, ShapeType.Hexagon);
134             shape15.FillColor = Color.DarkCyan;
135             shape15.StrokeColor = Color.White;
136             shape15.LineStyle = ShapeLineStyle.Single;
137             shape15.HorizontalPosition = 140;
138             shape15.VerticalPosition = 140;
139 
140             //插入一个不规则图形
141             ShapeObject shape16 = para1.AppendShape(50, 50, ShapeType.IrregularSeal1);
142             shape16.FillColor = Color.DeepPink;
143             shape16.StrokeColor = Color.White;
144             shape16.LineStyle = ShapeLineStyle.Single;
145             shape16.HorizontalPosition = 200;
146             shape16.VerticalPosition = 140;
147 
148             //插入一个月亮形状
149             ShapeObject shape17 = para1.AppendShape(50, 50, ShapeType.Moon);
150             shape17.FillColor = Color.Violet;
151             shape17.StrokeColor = Color.White;
152             shape17.LineStyle = ShapeLineStyle.Single;
153             shape17.HorizontalPosition = 260;
154             shape17.VerticalPosition = 140;
155 
156             //插入一个"禁止"形状
157             ShapeObject shape18 = para1.AppendShape(50, 50, ShapeType.NoSmoking);
158             shape18.FillColor = Color.Yellow;
159             shape18.StrokeColor = Color.Goldenrod;
160             shape18.LineStyle = ShapeLineStyle.Single;
161             shape18.HorizontalPosition = 320;
162             shape18.VerticalPosition = 140;
163 
164             //保存并打开文档
165             doc.SaveToFile("InsertShapes.docx", FileFormat.Docx2010);
166             System.Diagnostics.Process.Start("InsertShapes.docx");
167         }
168     }
169 }

View Code

 

步骤一:初阶化Presentation类实例,并加载文书档案

演示代码

 

(二)添加组合造型

步骤1:添加如下using指令

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

 

步骤二:成立文书档案,添加section、paragraph

Document doc = new Document();
Section sec = doc.AddSection();
Paragraph para1 = sec.AddParagraph();

 

手续三:添加文字,并选用格式到文字

para1.AppendText("中日文化交流");
ParagraphStyle style1 = new ParagraphStyle(doc);
style1.Name = "titleStyle";
style1.CharacterFormat.Bold = true;
style1.CharacterFormat.FontName = "隶书";
style1.CharacterFormat.FontSize = 30f;
doc.Styles.Add(style1);
para1.ApplyStyle("titleStyle");
para1.Format.HorizontalAlignment = HorizontalAlignment.Center;

 

步骤四:实例化段落2,并创办3个形象组合,并设置大小

//实例化段落2
Paragraph para2 = sec.AddParagraph();
//创建一个形状组合并设置大小
ShapeGroup shapegr = para2.AppendShapeGroup(300, 300);

 

步骤5:绘制3个神州国旗,那里须要组合造型矩形和伍角星形,并填写相应的水彩

 //添加一个矩形到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Rectangle)
            {
                Width = 900,
                Height = 500,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.Red,
                StrokeColor = Color.Red,                
                StrokeWeight = 1,
            });

            //添加第一个五角星到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
            {
                Width = 100,
                Height = 100,
                VerticalPosition = 90,
                HorizontalPosition = 90,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.Yellow,
                StrokeColor = Color.Yellow,
                StrokeWeight = 1,
            });
            //添加第二个五角星到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
            {
                Width = 50,
                Height = 50,
                VerticalPosition = 40,
                HorizontalPosition = 210,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.Yellow,
                StrokeColor = Color.Yellow,
                StrokeWeight = 1,
            });
            //添加第三个五角星到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
            {
                Width = 50,
                Height = 50,
                VerticalPosition = 80,
                HorizontalPosition = 280,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.Yellow,
                StrokeColor = Color.Yellow,
                StrokeWeight = 1,
            });
            //添加第四个五角星到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
            {
                Width = 50,
                Height = 50,
                VerticalPosition = 160,
                HorizontalPosition = 280,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.Yellow,
                StrokeColor = Color.Yellow,
                StrokeWeight = 1,
            });
            //添加第五个五角星到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
            {
                Width = 50,
                Height = 50,
                VerticalPosition = 220,
                HorizontalPosition = 210,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.Yellow,
                StrokeColor = Color.Yellow,
                StrokeWeight = 1,
            });

 

手续陆:绘制三个日本国旗,供给结合形象矩形和圆形,并填写颜色

//绘制一个矩形并添加到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Rectangle)
            {
                Width = 900,
                Height = 500,
                VerticalPosition = 700,
                HorizontalPosition = 600,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.WhiteSmoke,
                StrokeColor = Color.WhiteSmoke,
                StrokeWeight = 1,
            });
            //绘制一个圆形并添加到形状组合
            shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Ellipse)
            {
                Width = 250,
                Height = 250,
                VerticalPosition = 800,
                HorizontalPosition = 900,
                LineStyle = ShapeLineStyle.Single,
                FillColor = Color.Red,
                StrokeColor = Color.Red,
                StrokeWeight = 1,
            });

 

步骤柒:保存文书档案

//保存并打开文档
doc.SaveToFile("InsertShapegroups.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("InsertShapegroups.docx");

 

加上遵从:

亚洲必赢官网 6

(此时的图纸是整合后的功力,任意拖动图形不会并发各样形态分离、错位的气象。)

全副代码:

亚洲必赢官网 7亚洲必赢官网 8

  1 using Spire.Doc;
  2 using Spire.Doc.Documents;
  3 using Spire.Doc.Fields;
  4 using System.Drawing;
  5 
  6 namespace InsertShapesGroup_Doc
  7 {
  8     class Program
  9     {
 10         static void Main(string[] args)
 11         {
 12             //创建一个Document实例并添加section及paragraph
 13             Document doc = new Document();
 14             Section sec = doc.AddSection();
 15             Paragraph para1 = sec.AddParagraph();
 16             //添加文字,并应用格式到文字
 17             para1.AppendText("中日文化交流");
 18             ParagraphStyle style1 = new ParagraphStyle(doc);
 19             style1.Name = "titleStyle";
 20             style1.CharacterFormat.Bold = true;
 21             style1.CharacterFormat.FontName = "隶书";
 22             style1.CharacterFormat.FontSize = 30f;
 23             doc.Styles.Add(style1);
 24             para1.ApplyStyle("titleStyle");
 25             para1.Format.HorizontalAlignment = HorizontalAlignment.Center;
 26 
 27             //实例化段落2
 28             Paragraph para2 = sec.AddParagraph();
 29             //创建一个形状组合并设置大小
 30             ShapeGroup shapegr = para2.AppendShapeGroup(300, 300);
 31 
 32             //添加一个矩形到形状组合
 33             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Rectangle)
 34             {
 35                 Width = 900,
 36                 Height = 500,
 37                 LineStyle = ShapeLineStyle.Single,
 38                 FillColor = Color.Red,
 39                 StrokeColor = Color.Red,                
 40                 StrokeWeight = 1,
 41             });
 42 
 43             //添加第一个五角星到形状组合
 44             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
 45             {
 46                 Width = 100,
 47                 Height = 100,
 48                 VerticalPosition = 90,
 49                 HorizontalPosition = 90,
 50                 LineStyle = ShapeLineStyle.Single,
 51                 FillColor = Color.Yellow,
 52                 StrokeColor = Color.Yellow,
 53                 StrokeWeight = 1,
 54             });
 55             //添加第二个五角星到形状组合
 56             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
 57             {
 58                 Width = 50,
 59                 Height = 50,
 60                 VerticalPosition = 40,
 61                 HorizontalPosition = 210,
 62                 LineStyle = ShapeLineStyle.Single,
 63                 FillColor = Color.Yellow,
 64                 StrokeColor = Color.Yellow,
 65                 StrokeWeight = 1,
 66             });
 67             //添加第三个五角星到形状组合
 68             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
 69             {
 70                 Width = 50,
 71                 Height = 50,
 72                 VerticalPosition = 80,
 73                 HorizontalPosition = 280,
 74                 LineStyle = ShapeLineStyle.Single,
 75                 FillColor = Color.Yellow,
 76                 StrokeColor = Color.Yellow,
 77                 StrokeWeight = 1,
 78             });
 79             //添加第四个五角星到形状组合
 80             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
 81             {
 82                 Width = 50,
 83                 Height = 50,
 84                 VerticalPosition = 160,
 85                 HorizontalPosition = 280,
 86                 LineStyle = ShapeLineStyle.Single,
 87                 FillColor = Color.Yellow,
 88                 StrokeColor = Color.Yellow,
 89                 StrokeWeight = 1,
 90             });
 91             //添加第五个五角星到形状组合
 92             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Star)
 93             {
 94                 Width = 50,
 95                 Height = 50,
 96                 VerticalPosition = 220,
 97                 HorizontalPosition = 210,
 98                 LineStyle = ShapeLineStyle.Single,
 99                 FillColor = Color.Yellow,
100                 StrokeColor = Color.Yellow,
101                 StrokeWeight = 1,
102             });
103 
104             //绘制一个矩形并添加到形状组合
105             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Rectangle)
106             {
107                 Width = 900,
108                 Height = 500,
109                 VerticalPosition = 700,
110                 HorizontalPosition = 600,
111                 LineStyle = ShapeLineStyle.Single,
112                 FillColor = Color.WhiteSmoke,
113                 StrokeColor = Color.Wheat,
114                 StrokeWeight = 1,
115             });
116             //绘制一个圆形并添加到形状组合
117             shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Ellipse)
118             {
119                 Width = 250,
120                 Height = 250,
121                 VerticalPosition = 800,
122                 HorizontalPosition = 900,
123                 LineStyle = ShapeLineStyle.Single,
124                 FillColor = Color.Red,
125                 StrokeColor = Color.Red,
126                 StrokeWeight = 1,
127             });    
128 
129             //保存并打开文档
130             doc.SaveToFile("InsertShapegroups.docx", FileFormat.Docx2010);
131             System.Diagnostics.Process.Start("InsertShapegroups.docx");
132         }
133     }
134 }

View Code

 

如上全部是有关Word中绘制图形形状的始末。如需转发,请评释出处!

多谢阅读!

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

一. 插入图片到Word批注

步骤 1:添加using指令

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

步骤 二:创立文书档案,加载测试文件

Document doc = new Document();
doc.LoadFromFile("testfile.docx");

手续 三 :获取段落

Paragraph paragraph = doc.Sections[0].Paragraphs[2];

手续 四 :添加文本、图片到批注

Comment comment = paragraph.AppendComment("探索黑科技,小米为发烧而生!");
comment.Format.Author = "Administor";  

DocPicture docPicture = new DocPicture(doc);
Image img = Image.FromFile("mi.png");
docPicture.LoadImage(img);
//插入图片到批注
comment.Body.AddParagraph().ChildObjects.Add(docPicture);

手续 5 :保存文件

doc.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");

 

测试结果:

亚洲必赢官网 9

C#成套代码:

亚洲必赢官网 10亚洲必赢官网 11

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace InsertImgToComment_Doc
{
    class Program
    {
        static void Main(string[] args)
        {
            //实例化Document类,加载文档
            Document doc = new Document();
            doc.LoadFromFile("testfile.docx");

            //获取需要添加批注的段落
            Paragraph paragraph = doc.Sections[0].Paragraphs[2];

            //添加文本批注内容、批注作者
            Comment comment = paragraph.AppendComment("探索黑科技,小米为发烧而生!");
            comment.Format.Author = "Administor";

            //实例化DocPicture类,加载图片
            DocPicture docPicture = new DocPicture(doc);
            Image img = Image.FromFile("mi.png");
            docPicture.LoadImage(img);
            //插入图片到批注
            comment.Body.AddParagraph().ChildObjects.Add(docPicture);

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

View Code

VB.NET代码:

亚洲必赢官网 12亚洲必赢官网 13

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing

Namespace InsertImgToComment_Doc
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim doc As Document = New Document()
            doc.LoadFromFile("testfile.docx")
            Dim paragraph As Paragraph = doc.Sections(0).Paragraphs(2)
            Dim comment As Comment = paragraph.AppendComment("探索黑科技,小米为发烧而生!")
            comment.Format.Author = "Administor"
            Dim docPicture As DocPicture = New DocPicture(doc)
            Dim img As Image = Image.FromFile("mi.png")
            docPicture.LoadImage(img)
            comment.Body.AddParagraph().ChildObjects.Add(docPicture)
            doc.SaveToFile("result.docx", FileFormat.Docx2013)
            System.Diagnostics.Process.Start("result.docx")
        End Sub
    End Class
End Namespace

View Code

 

使用工具:Spire.PDF for .NET
4.0

手续二:起初化二个Font类实例,并实例化字体格式

2.读取Word批注

步骤 1 :添加using指令

using System.Text;
using System.IO;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

手续 二 :创立实例,加载文书档案

Document doc = new Document();
doc.LoadFromFile("test.docx");

亚洲必赢官网,手续 3 :将批注内容写入Txt文书档案

//实例化StringBuilder类
StringBuilder SB = new StringBuilder();
//遍历所有word批注,将批注内容写入Txt文档
foreach (Comment comment in doc.Comments)
{
    foreach (Paragraph p in comment.Body.Paragraphs)
    {
        SB.AppendLine(p.Text);
    }
}
File.WriteAllText("CommentExtraction.txt", SB.ToString());
System.Diagnostics.Process.Start("CommentExtraction.txt");

亚洲必赢官网 14

C# 全体代码:

亚洲必赢官网 15亚洲必赢官网 16

using System.Text;
using System.IO;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace ExtractComments
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建实例,加载文档
            Document doc = new Document();
            doc.LoadFromFile("test.docx");

            //实例化StringBuilder类
            StringBuilder SB = new StringBuilder();
            //遍历所有word批注,将批注内容写入Txt文档
            foreach (Comment comment in doc.Comments)
            {
                foreach (Paragraph p in comment.Body.Paragraphs)
                {
                    SB.AppendLine(p.Text);
                }
            }
            File.WriteAllText("CommentExtraction.txt", SB.ToString());
            System.Diagnostics.Process.Start("CommentExtraction.txt");
        }
    }
}

View Code

VB.NET 代码

亚洲必赢官网 17亚洲必赢官网 18

Imports System.Text
Imports System.IO
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace ExtractComments
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim doc As Document = New Document()
            doc.LoadFromFile("test.docx")
            Dim SB As StringBuilder = New StringBuilder()

            For Each comment As Comment In doc.Comments

                For Each p As Paragraph In comment.Body.Paragraphs
                    SB.AppendLine(p.Text)
                Next
            Next

            File.WriteAllText("CommentExtraction.txt", SB.ToString())
            System.Diagnostics.Process.Start("CommentExtraction.txt")
        End Sub
    End Class
End Namespace

View Code

 

PS:
安装该类库后,注意在先后中援引Spire.PDF.dll后在开始展览代码编辑,dll文件可在装置路径下的Bin文件夹中赢得。

Font stringFont = new Font("Arial", 90);
Size size = TextRenderer.MeasureText("内部资料", stringFont);

3. 复苏Word批注内容

步骤 1 :添加using指令 

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

手续 二 :成立实例

Document doc = new Document();
doc.LoadFromFile("test.docx");

手续 三 :获取批注

Comment comment = doc.Comments[0];

手续 四 :回复批注

Comment replyComment = new Comment(doc);
replyComment.Format.Author = "Adam";
replyComment.Body.AddParagraph().AppendText("这条批注内容请再丰富一下,内容有些单调");
comment.ReplyToComment(replyComment);

手续 5 :保存文件

doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("ReplyToComment.docx");

 

测试结果:

亚洲必赢官网 19

C# 全体代码:

亚洲必赢官网 20亚洲必赢官网 21

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

namespace ReplyComment_Doc
{
    class Program
    {
        static void Main(string[] args)
        {
            //实例化Document类,加载文件
            Document doc = new Document();
            doc.LoadFromFile("test.docx");

            //获取第一个批注
            Comment comment = doc.Comments[0];

            //实例化Comment类,添加批注回复作者以及回复内容
            Comment replyComment = new Comment(doc);
            replyComment.Format.Author = "Adam";
            replyComment.Body.AddParagraph().AppendText("这条批注内容请再丰富一下,内容有些单调");
            comment.ReplyToComment(replyComment);

            //保存文件并打开
            doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("ReplyToComment.docx");
        }
    }
}

View Code

VB.NET 代码:

亚洲必赢官网 22亚洲必赢官网 23

Imports Spire.Doc
Imports Spire.Doc.Fields

Namespace ReplyComment_Doc
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim doc As Document = New Document()
            doc.LoadFromFile("test.docx")
            Dim comment As Comment = doc.Comments(0)
            Dim replyComment As Comment = New Comment(doc)
            replyComment.Format.Author = "Adam"
            replyComment.Body.AddParagraph().AppendText("这条批注内容请再丰富一下,内容有些单调")
            comment.ReplyToComment(replyComment)
            doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013)
            System.Diagnostics.Process.Start("ReplyToComment.docx")
        End Sub
    End Class
End Namespace

View Code

以上为这一次关于操作Word批注的全体内容。

(本文完)

如需转发,请申明出处。

 亚洲必赢官网 24

步骤3:绘制1个shape并内定大小、填充颜色、边框颜色和旋转角度

 

RectangleF rect = new RectangleF((ppt.SlideSize.Size.Width - size.Width) / 2, (ppt.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height);
IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Rotation = -45;

【示例一】绘制倾斜样式的公文

 步骤一:创设实例

PdfDocument doc = new PdfDocument(); 
PdfPageBase page = doc.Pages.Add();    

步骤二:保存画布状态

PdfGraphicsState state = page.Canvas.Save();

步骤三:实例化字体,创设格式刷

PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);
PdfSolidBrush brush3 = new PdfSolidBrush(Color.LightPink);

手续4:钦命文本在画布上的坐标,并点名文本的横向、纵向的拉伸度

page.Canvas.TranslateTransform(10, 100);
page.Canvas.ScaleTransform(1f, 0.6f);

手续五:绘制文本

 //绘制倾斜样式的文本
 page.Canvas.SkewTransform(-10, 0);
 page.Canvas.DrawString("THERE IS NO ROYAL ROAD TO LEARNING. ", font, brush1, 0, 0);
 page.Canvas.SkewTransform(10, 10);
 page.Canvas.DrawString("Books, like friends, should be few and well chosen. ", font, brush2, 10, 50);

 //绘制缩放类型的文本
 page.Canvas.ScaleTransform(1f, -1f);
 page.Canvas.DrawString("Books, like friends, should be few and well chosen.", font, brush3, 10, -2 * 50);

手续6:再一次保存画布

page.Canvas.Restore(state);

手续柒:保存文件

doc.SaveToFile("DrawText.pdf");
System.Diagnostics.Process.Start("DrawText.pdf");

测试效果:

亚洲必赢官网 25

整套代码:

亚洲必赢官网 26亚洲必赢官网 27

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

namespace DrawTextOfDifferentStyles_PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument(); //创建一个PDF文档
            PdfPageBase page = doc.Pages.Add(); //添加页   

            PdfGraphicsState state = page.Canvas.Save();

            //实例化字体,创建格式刷           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
            PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
            PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);
            PdfSolidBrush brush3 = new PdfSolidBrush(Color.LightPink);

            page.Canvas.TranslateTransform(10, 100);//指定文本在画布上的坐标位置
            page.Canvas.ScaleTransform(1f, 0.6f);//指定文本的横向、纵向的拉伸度

            //绘制倾斜样式的文本
            page.Canvas.SkewTransform(-10, 0);
            page.Canvas.DrawString("THERE IS NO ROYAL ROAD TO LEARNING. ", font, brush1, 0, 0);
            page.Canvas.SkewTransform(10, 10);
            page.Canvas.DrawString("Books, like friends, should be few and well chosen. ", font, brush2, 10, 50);

            //绘制缩放类型的文本
            page.Canvas.ScaleTransform(1f, -1f);
            page.Canvas.DrawString("Books, like friends, should be few and well chosen.", font, brush3, 10, -2 * 50);

            //再次保存画布
            page.Canvas.Restore(state);

            //保存并打开文档
            doc.SaveToFile("DrawText.pdf");
            System.Diagnostics.Process.Start("DrawText.pdf");
        }
    }
}

View Code

 

 

步骤四:设定形状属性为掩护属性

【示例贰】绘制中央旋转图形

 步骤一:创设实例

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add(); 

手续2:保存画布

 PdfGraphicsState state = page.Canvas.Save();

手续叁:实例化字体类,创制格式刷

PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
PdfSolidBrush brush = new PdfSolidBrush(Color.BlueViolet);

手续四:设定字符串布局格式,并点名文本在画布中的地点

PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
float x = 400;
float y = 600;
page.Canvas.TranslateTransform(x, y);

手续5:绘制文本,应用格式

//指定文本绘制数量
for (int i = 0; i < 12; i++)
{
    //设置文本按顺时针方向旋转排列(文本偏移间隔30度)
    page.Canvas.RotateTransform(30);
    //绘制文本并应用格式                
    page.Canvas.DrawString("Every tide has its ebb.", font, brush, 10, 0, centerAlignment);
}

手续6:再次保存画布

page.Canvas.Restore(state);

手续七:保存文书档案

doc.SaveToFile("DrawText.pdf");
System.Diagnostics.Process.Start("DrawText.pdf");

测试结果:

(那里做了多少个不等样式的demo,能够相比看下效果)

亚洲必赢官网 28

全总代码:

亚洲必赢官网 29亚洲必赢官网 30

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

namespace _3
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument(); //创建一个PDF文档
            PdfPageBase page = doc.Pages.Add(); //添加页   

            PdfGraphicsState state = page.Canvas.Save();

            //实例化字体,创建格式刷            
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.BlueViolet);

            //设定字符串布局格式,并指定文本在画布中的位置
            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            float x = 400;
            float y = 600;
            //绘制文本并应用格式
            page.Canvas.TranslateTransform(x, y);
            //指定文本绘制数量
            for (int i = 0; i < 12; i++)
            {
                //设置文本按顺时针方向旋转排列(文本偏移间隔30度)
                page.Canvas.RotateTransform(30);
                //绘制文本并应用格式                
                page.Canvas.DrawString("Every tide has its ebb.", font, brush, 10, 0, centerAlignment);
            }
            //再次保存画布
            page.Canvas.Restore(state);

            //保存并打开文档
            doc.SaveToFile("DrawText.pdf");
            System.Diagnostics.Process.Start("DrawText.pdf");
        }
    }
}

View Code

 

以上是此番关于绘制分裂风格类型文本的全体内容,如需转发,请注明出处。

(本文完)

shape.Locking.SelectionProtection = true;
shape.Line.FillType = FillFormatType.None;

手续5:设置文本大小、颜色

shape.TextFrame.Text = "内部资料";
TextRange textRange = shape.TextFrame.TextRange;
textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.Gray);
textRange.FontHeight = 45;

手续陆:保存文书档案

ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2010);

形成以上代码步骤后,调节和测试运维品种先后,生成文书(可在该品种文件中bin>Debug中查看),如下图所示:

 亚洲必赢官网 31

全方位代码:

亚洲必赢官网 32亚洲必赢官网 33

using System;
using System.Text;
using Spire.Presentation;
using System.Drawing;
using Spire.Presentation.Drawing;
using System.Windows.Forms;

namespace InsertWatermark_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化一个Presentation类实例并加载文档
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

            //初始化一个Font类字体实例并实例化字体格式
            Font stringFont = new Font("Arial", 90);
            Size size = TextRenderer.MeasureText("内部资料", stringFont);

            //绘制一个Shape并指定大小、填充颜色、边框颜色和旋转度
            RectangleF rect = new RectangleF((ppt.SlideSize.Size.Width - size.Width) / 2, (ppt.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height);
            IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.Rotation = -45;

            //设定形状属性为保护属性
            shape.Locking.SelectionProtection = true;
            shape.Line.FillType = FillFormatType.None;

            //设置文本大小、颜色
            shape.TextFrame.Text = "内部资料";
            TextRange textRange = shape.TextFrame.TextRange;
            textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange.Fill.SolidColor.Color = Color.FromArgb(150, Color.LightBlue);
            textRange.FontHeight = 90;

            //保存文档
            ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2010);
        }
    }

View full Code

 

2.添加图片水印

手续一:初步化三个Presentation类实例并加载文书档案

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

步骤2: 为率先张幻灯片设置背景图片类型和样式

ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;

手续三:加载图片并为第1张幻灯片设置水印

Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\images\1.jpg");
IImageData image = ppt.Images.Append(img);
ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

步骤四:保存文书档案

 ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);

亚洲必赢官网 34

任何代码:

亚洲必赢官网 35亚洲必赢官网 36

using System;
using System.Drawing;
using Spire.Presentation;
using Spire.Presentation.Drawing;

namespace ImageWatermark_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化一个Presentation类实例并加载文档
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

            //为第一张幻灯片设置背景图片类型和样式
            ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
            ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
            ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;

            //加载图片并为第一张幻灯片设置水印效果
            Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\images\1.jpg");
            IImageData image = ppt.Images.Append(img);
            ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

            //保存文档
            ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);
        }
    }
}

View full Code

 

 

如上是对PPT添加水印的代码操作,希望该办法能提供赞助,谢谢阅读!

网站地图xml地图