运用C#给PDF文档增加解释的示例代码分享(图)【C#.Net教程】,C#,PDF,添加注释
作者:搜教程发布时间:2019-11-27分类:.Net教程浏览:30评论:0
导读:本文将实例报告C#中怎样运用免费组件给PDF文档增加文本解释,包含自在文本解释。自在文本解释能许可我们自定义它的作风和表面,异常具有实用价值整顿文档时,我们可能会需要在一些...
本文将实例报告C#中怎样运用免费组件给PDF文档增加文本解释,包含自在文本解释。自在文本解释能许可我们自定义它的作风和表面,异常具有实用价值
整顿文档时,我们可能会需要在一些或一段笔墨上增加解释加以申明,那怎样以编程的体式格局完成呢?本文将实例报告C#中怎样运用免费组件给PDF文档增加文本解释,包含自在文本解释。自在文本解释能许可我们自定义它的作风和表面,异常具有实用价值。
起首,下载这个免费版组件Free Spire.PDF。组件下载安装后,Visual Studio建立C#控制台项目,增加bin文件夹的.DLL作为援用以及以下定名空间:
using System; using System.Drawing; using System.Windows.Forms; using Spire.Pdf; using Spire.Pdf.Graphics; using Spire.Pdf.Annotations;
如今我们就来细致看看怎样给新建的文档增加解释的。
步骤1:新建一个PDF文档对象,再增加一个新页面。
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add();
步骤2:文档中增加文本,并设置文本的位置、字体大小、色彩。
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 13); string text = "HelloWorld"; PointF point = new PointF(200, 100); page.Canvas.DrawString(text, font, PdfBrushes.Red, point);
步骤3:给文本增加解释,并设置解释的边框、色彩及位置。
PdfTextMarkupAnnotation annotation1 = new PdfTextMarkupAnnotation("管理员", "一般来说,这是每一种计算机编程言语中最基础、最简朴的顺序", text, new PointF(0, 0), font); annotation1.Border = new PdfAnnotationBorder(0.75f); annotation1.TextMarkupColor = Color.Green; annotation1.Location = new PointF(point.X + doc.PageSettings.Margins.Left, point.Y + doc.PageSettings.Margins.Left);
步骤4:将解释增加到页面,末了保留文档。
(page as PdfNewPage).Annotations.Add(annotation1); doc.SaveToFile("result.pdf");
这是增加解释后的效果图:
悉数代码:
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add(); PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 13); string text = "HelloWorld"; PointF point = new PointF(200, 100); page.Canvas.DrawString(text, font, PdfBrushes.Red, point); PdfTextMarkupAnnotation annotation1 = new PdfTextMarkupAnnotation("管理员", "一般来说,这是每一种计算机编程言语中最基础、最简朴的顺序", text, new PointF(0, 0), font); annotation1.Border = new PdfAnnotationBorder(0.75f); annotation1.TextMarkupColor = Color.Green; annotation1.Location = new PointF(point.X + doc.PageSettings.Margins.Left, point.Y + doc.PageSettings.Margins.Left); (page as PdfNewPage).Annotations.Add(annotation1); doc.SaveToFile("result.pdf"); System.Diagnostics.Process.Start("result.pdf");
增加自在文本解释
一样,给文档增加自在文本解释也相对简朴。
步骤1:新建一个PDF文档对象,并增加一个新页面。
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add();
步骤2:初始化一个PdfFreeTextAnnotation,然后自定义解释的文本。
RectangleF rect = new RectangleF(0, 40, 150, 50); PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(rect); textAnnotation.Text = "Free text annotation ";
步骤3:设置解释的属性,包含字体、添补色彩、边框色彩和透明度。
PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 10); PdfAnnotationBorder border = new PdfAnnotationBorder(1f); textAnnotation.Font = font; textAnnotation.Border = border; textAnnotation.BorderColor = Color. Purple; textAnnotation.LineEndingStyle = PdfLineEndingStyle.Circle; textAnnotation.Color = Color. Pink; textAnnotation.Opacity = 0.8f;
步骤4:增加解释到页面。
page.AnnotationsWidget.Add(textAnnotation);
步骤5:保留并从新打开文档。
doc.SaveToFile("FreeTextAnnotation.pdf", FileFormat.PDF); System.Diagnostics.Process.Start("FreeTextAnnotation.pdf");
这是增加自在文本解释的效果图:
悉数代码:
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add(); RectangleF rect = new RectangleF(0, 40, 150, 50); PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(rect); textAnnotation.Text = "Free text annotation "; PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 10); PdfAnnotationBorder border = new PdfAnnotationBorder(1f); textAnnotation.Font = font; textAnnotation.Border = border; textAnnotation.BorderColor = Color. Purple; textAnnotation.LineEndingStyle = PdfLineEndingStyle.Circle; textAnnotation.Color = Color.Pink; textAnnotation.Opacity = 0.8f; page.AnnotationsWidget.Add(textAnnotation); doc.SaveToFile("FreeTextAnnotation.pdf", FileFormat.PDF); System.Diagnostics.Process.Start("FreeTextAnnotation.pdf");
以上就是运用C#给PDF文档增加解释的示例代码分享(图)的细致内容,更多请关注ki4网别的相干文章!
相关推荐
- Icecream PDF Editor如何提取PDF文件页面?PDF页面提取 完美教程文章资讯
- C#对XML读写的代码实例【XML教程】,C#,XML读写
- C#中经由过程xpath查找xml的指定元素的代码实例【XML教程】,C#,xpath,xml
- C#怎样盘算2个字符串类似度的示例代码分享【C#.Net教程】,C#,字符串,相似度
- 详解C#罕见运用函数的实例总结【C#.Net教程】,C#,应用函数
- C#剖析XML文件的代码实例分享【C#.Net教程】,C#,XML
- C# 怎样设置体系的默许打印机的简朴代码示例【C#.Net教程】,C#,打印机
- 详解C#程序员开辟WinForm必需晓得的Window音讯大全的示例代码【C#.Net教程】,C#,WinForm,Window
- C# HttpHandler 异步监听要求的代码详解【C#.Net教程】,C# ,HttpHandler ,异步监听
- C# Json 序列化与反序列化二【C#.Net教程】,C#,序列化,反序列化
你 发表评论:
欢迎- .Net教程排行
-
- 1案例分享c++ map的运用和 查找机能测试【C#.Net教程】,性能,map,c++
- 2细致引见C# string花样的日期时候字符串转为DateTime范例的要领【C#.Net教程】,C#,string,DateTime
- 3c#怎样运用?c#的基础语法【C#.Net教程】,c#,关键字
- 4详解ASP.NET中衔接数据库设置要领【C#.Net教程】,ASP.NET,数据库,配置
- 5C# DataSet机能最好实践【C#.Net教程】,C#,DataSet
- 6.net和c#有什么区别【C#.Net教程】,.net,c#
- 7C#_挪用封装的一个类完成导出Excel表格的功用【C#.Net教程】,C# Excel表格
- 8asp .net 面试题及答案分享【C#.Net教程】,.net,自己,整理,问题,面试
- 9让WebAPI 返回JSON花样的数据实例教程【C#.Net教程】,javascript,WebAPI,JSON,api,web,搭建,返回
- 最新文章
- 广而告之