该文将介绍如何使用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
效果图: