Word控件Spire.Doc 【图像形状】教程(5) 如何在 C# 中将文本环绕在图像周围

本文将向您展示如何在 C# 中将文本环绕在图像周围,欢迎查阅!

当我们将图像添加到word文档中时,我们当然希望将它准确地移动到我们想要使页面整洁美观的位置。借助 Spire.Doc,我们可以设置环绕样式来调整图像的位置。通常有七种环绕样式:In Line with Text、Square、Tight、Through、Top and Bottom、Behind the Text、In Front of Text,Spire.Doc 都支持。本文将向您展示如何在 C# 中将文本环绕在图像周围。步骤如下:

第 1 步创建一个新的 word 文档并从文件中加载文档。

Document document = new Document();document.LoadFromFile("Sample.docx");

第 2 步为第一部分添加一个段落。

Paragraph paragraph = document.Sections[0].AddParagraph();

第 3 步在段落中添加图片。

DocPicture picture = paragraph.AppendPicture(Image.FromFile("image.jpg"));

第 4 步将文本环绕样式设置为方形。

picture.TextWrappingStyle = TextWrappingStyle.Square;

第 5 步将文本环绕类型设置为两者。

picture.TextWrappingType = TextWrappingType.Both;

第 6 步将文档保存到文件并进行处理。

document.SaveToFile(output,FileFormat.Docx);System.Diagnostics.Process.Start(output);

图像周围扭曲文本的有效截图:

如何在 C# 中将文本环绕在图像周围

完整代码

using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;using System.Drawing;namespace wrap_text_around_image{class Program{static void Main(string[] args){Document document = new Document();document.LoadFromFile("Sample.docx");Paragraph paragraph = document.Sections[0].AddParagraph();DocPicture picture = paragraph.AppendPicture(Image.FromFile("image.jpg"));picture.TextWrappingStyle = TextWrappingStyle.Square;picture.TextWrappingType = TextWrappingType.Both;string output = "output.docx";document.SaveToFile(output,FileFormat.Docx);System.Diagnostics.Process.Start(output);}}}

以上便是如何在 C# 中将文本环绕在图像周围,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。


欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年9月6日
下一篇 2022年9月6日

相关推荐

发表回复

登录后才能评论