翻译|使用教程|编辑:李显亮|2019-08-16 15:21:45.663|阅读 396 次
概述:在接下来的系列教程中,将为开发者带来Aspose.PDF for .NET的一系列使用教程,例如进行文档间的转换,如何标记PDF文件,如何使用表单和图表等等。本文讲解如何设置FreeTextAnnotation格式化和删除单词。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Aspose.PDF for .NET是一种高PDF处理和解析API,用于在跨平台应用程序中执行文档管理和操作任务。API可以轻松用于生成、修改、转换、渲染、保护和打印PDF文档,而无需使用Adobe Acrobat。此外,API还提供PDF压缩选项,表格创建和操作,图形和图像功能,广泛的超链接功能,印章和水印任务,扩展的安全控制和自定义字体处理。
在接下来的系列教程中,将为开发者带来Aspose.PDF for .NET的一系列使用教程,例如进行文档间的转换,如何标记PDF文件,如何使用表单和图表等等。
注释包含在Page对象的AnnotationCollection集合中。 将FreeTextAnnotation添加到PDF文档时,可以使用DefaultAppearance类指定格式信息,如字体,大小,颜色等。 也可以使用TextStyle属性指定格式信息。
TextStyle类支持使用默认样式条目。 此类允许您设置颜色,字体大小和字体名称:
以下代码段显示了如何添加具有特定文本格式的FreeTextAnnotation:
//文档目录的路径。 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); //打开文档 Document pdfDocument = new Document(dataDir + "SetFreeTextAnnotationFormatting.pdf"); //实例化DefaultAppearance对象 DefaultAppearance default_appearance = new DefaultAppearance("Arial", 28, System.Drawing.Color.Red); // 创建注释 FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance); //指定注释的内容 freetext.Contents = "Free Text"; //将注释添加到页面的注释集合中 pdfDocument.Pages[1].Annotations.Add(freetext); dataDir = dataDir + "SetFreeTextAnnotationFormatting_out.pdf"; //保存更新后的文档 pdfDocument.Save(dataDir);
spose.PDF for .NET允许您在PDF文档中添加,删除和更新注释。 其中一个类允许您删除注释。 当您想要删除文档中的一个或多个文本片段时,这非常有用。 注释保存在Page对象的AnnotationCollection集合中。 名为StrikeOutAnnotation的类可用于向PDF文档添加删除注释。
要删除某个TextFragment:
以下代码段显示了如何搜索特定的TextFragment并向该对象添加StrikeOutAnnotation:
//文档目录的路径。 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); //打开文档 Document document = new Document(dataDir + "input.pdf"); //创建TextFragment Absorber实例以搜索特定文本片段 Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber("Estoque"); //遍历PDF文档页面 for (int i = 1; i <= document.Pages.Count; i++) { //获取PDF文档的第一页 Page page = document.Pages[1]; page.Accept(textFragmentAbsorber); } // 创建吸收文本的集合 Aspose.Pdf.Text.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments; //迭代上面的集合 for (int j = 1; j <= textFragmentCollection.Count; j++) { Aspose.Pdf.Text.TextFragment textFragment = textFragmentCollection[j]; //获取TextFragment对象的矩形尺寸 Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle( (float)textFragment.Position.XIndent, (float)textFragment.Position.YIndent, (float)textFragment.Position.XIndent + (float)textFragment.Rectangle.Width, (float)textFragment.Position.YIndent + (float)textFragment.Rectangle.Height); // 实例化StrikeOut Annotation实例 StrikeOutAnnotation strikeOut = new StrikeOutAnnotation(textFragment.Page, rect); // 为注释设置不透明度 strikeOut.Opacity = .80f; //设置注释实例的边框 strikeOut.Border = new Border(strikeOut); //设置注释的颜色 strikeOut.Color = Aspose.Pdf.Color.Red; //将注释添加到TextFragment的注释集合中 textFragment.Page.Annotations.Add(strikeOut); } dataDir = dataDir + "StrikeOutWords_out.pdf"; document.Save(dataDir);
*想要购买Aspose.PDF for .NET正版授权的朋友可以联系在线客服了解详情哦~
欢迎加入ASPOSE技术交流QQ群,各类资源及时分享,技术问题交流讨论!(扫描下方二维码加入群聊)
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com