PDF处理控件Aspose.Pdf使用教程:为FreeTextAnnotation设置格式

Aspose.PDF 是一款高级PDF处理API,可以在跨平台应用程序中轻松生成,修改,转换,呈现,保护和打印文档。无需使用Adobe Acrobat。此外,API提供压缩选项,表创建和处理,图形和图像功能,广泛的超链接功能,图章和水印任务,扩展的安全控件和自定义字体处理。本文将为你介绍如何在 C++ 中将PDF转换为Doc 、Docx 。

Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

Aspose.pdf 最新下载(qun:761297826)icon-default.png?t=N5F7https://www.evget.com/product/4118/download

注释都包含在一个特定的页面集合中,每个页面都有自己的注释集合。当添加FreeTextAnnotation在PDF文档中时,我们为之设定格式。使用DefaultAppearance设置字体、大小、颜色等或使用TextStyle属性指定格式信息。此外,我们还可以更新已经存在于现有的PDF文档的FreeTextAnnotation的格式。

[TextStyle] 允许设置字体样式、颜色和大小。

FontName (设置字体样式)

FontSize (获取或者设置默认字体大小)

System.Drawing.Color Color (获取或者设置字体颜色)

TextAligment Alignment (获取或设置注释中的文字对齐方式)

下面是添加指定格式的FreeTextAnnotation代码片段

C#

扫描二维码关注公众号,回复: 15335788 查看本文章
//open document
Document pdfDocument = new Document("c:/pdftest/TestReport.pdf");
// instantiate DefaultAppearance object
Aspose.Pdf.InteractiveFeatures.DefaultAppearance default_appearance = new DefaultAppearance("Arial", 28, System.Drawing.Color.Red);
//create annotation
FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance);
// specify the contents of annotation
freetext.Contents = "Free Text";
// add anootation to annotations collection of page
pdfDocument.Pages[1].Annotations.Add(freetext);
// save the updated document
pdfDocument.Save("c:/pdftest/Watermarked_output_FreeText.pdf");

VB.NET

'open document Dim pdfDocument As Document = New Document("c:/pdftest/TestReport.pdf") ' instantiate DefaultAppearance object Dim default_appearance As Aspose.Pdf.InteractiveFeatures.DefaultAppearance = New InteractiveFeatures.DefaultAppearance("Arial", 28, System.Drawing.Color.Red) 'create annotation Dim freetext As FreeTextAnnotation = New FreeTextAnnotation(pdfDocument.Pages(1), New Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance) ' specify the contents of annotation freetext.Contents = "Free Text" ' add anootation to annotations collection of page pdfDocument.Pages(1).Annotations.Add(freetext) ' save the updated document pdfDocument.Save("c:/pdftest/Watermarked_output_FreeText.pdf") 

下面是更新已有FreeTextAnnotation格式的代码片段

C#

Document doc1 = new Document("34471-2.pdf");
//set font size and color of the annotation:
(doc1.Pages[1].Annotations[1] as FreeTextAnnotation).TextStyle.FontSize = 18;
(doc1.Pages[1].Annotations[1] as FreeTextAnnotation).TextStyle.Color = System.Drawing.Color.Green;

VB.NET

Dim doc1 As Document = New Document("34471-2.pdf")
'set font size and color of the annotation:
CType(doc1.Pages(1).Annotations(1), FreeTextAnnotation).TextStyle.FontSize = 18
CType(doc1.Pages(1).Annotations(1), FreeTextAnnotation).TextStyle.Color = System.Drawing.Color.Green

猜你喜欢

转载自blog.csdn.net/m0_67129275/article/details/131242738