该文将介绍如何使用Spire.Doc for .NET 添加图章或电子章到Word文档。
C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace WordDemo
{
class Program
{
static void Main(string[] args)
{
//加载示例文档
Document doc = new Document();
doc.LoadFromFile("sample.docx");
//添加电子章
Image image = Image.FromFile("Stamp.png");
DocPicture picture = doc.Sections[0].Paragraphs[0].AppendPicture(image);
//指定电子章位置
picture.HorizontalPosition = 200f;
picture.VerticalPosition = 160f;
//设置电子章大小
picture.Width = 150;
picture.Height = 150;
//设置图片浮于文字上方
picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
//保存文档
doc.SaveToFile("Result.docx", FileFormat.Docx);
}
}
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace WordDemo
Class Program
Private Shared Sub Main(ByVal args() As String)
Dim doc As Document = New Document
doc.LoadFromFile("sample.docx")
Dim image As Image = Image.FromFile("Stamp.png")
Dim picture As DocPicture = doc.Sections(0).Paragraphs(0).AppendPicture(image)
picture.HorizontalPosition = 200!
picture.VerticalPosition = 160!
picture.Width = 150
picture.Height = 150
picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText
doc.SaveToFile("Result.docx", FileFormat.Docx)
End Sub
End Class
End Namespace
效果图: