当客户添加图片到Word文档里的时候,为了使文档看起来更美观,大多数时候需要对图片和文本位置进行调整,利用
Spire.Doc文档处理控件可以轻松实现文本环绕图片,开发人员可以设置wrapping样式,调整图片位置,通常有几种环绕样式:In Line with Text, Square, Tight, Through, Top and Bottom, Behind the Text, In Front of Text等,
Spire.Doc都支持这几种样式,怎么设置和使用这些样式可以具体参考下面的代码:
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);
}
}
}