>>可点击此处下载最新版测试。
将图像图章添加到 Word 文档
Spire.Doc for Java 允许开发人员使用下表中列出的核心类和方法来添加和格式化图像,使其看起来像 Word 文档中的图章。
姓名 | 描述 |
DocPicture 类 | 表示 Word 文档中的图片。 |
Paragraph.appendPicture() 方法 | 将图像附加到段落末尾。 |
DocPicture.setHorizontalPosition() 方法 | 设置图片的绝对水平位置。 |
DocPicture.setVerticalPosition() 方法 | 设置图片的绝对垂直位置。 |
DocPicture.setWidth() 方法 | 设置图片宽度。 |
DocPicture.setHeight 方法 | 设置图片高度。 |
DocPicture.setTextWrappingStyle() 方法 | 设置图片的文字环绕类型。 |
详细步骤如下:
- 创建一个文档实例。
- 使用Document.loadFromFile()方法加载 Word 文档。
- 使用ParagraphCollection.get()方法获取特定段落。
- 使用Paragraph.appendPicture()方法将图像添加到 Word 文档。
- 使用DocPicture类提供的方法设置图像的位置、大小和环绕样式。
- 使用Document.saveToFile()方法将文档保存到另一个文件。
import com.spire.doc.*;import com.spire.doc.documents.Paragraph;import com.spire.doc.documents.TextWrappingStyle;import com.spire.doc.fields.DocPicture;public class AddStamp { public static void main(String[] args) { //Create a Document instance Document doc = new Document(); //Load a Word document doc.loadFromFile("test.docx"); //Get the specific paragraph Section section = doc.getSections().get(0); Paragraph paragraph = section.getParagraphs().get(4); //Add an image DocPicture picture = paragraph.appendPicture("cert.png"); //Set the position of the image picture.setHorizontalPosition(240f); picture.setVerticalPosition(120f); //Set width and height of the image picture.setWidth(150); picture.setHeight(150); //Set wrapping style of the image to In_Front_Of_Text, so that it looks like a stamp picture.setTextWrappingStyle(TextWrappingStyle.In_Front_Of_Text); //Save the document to file doc.saveToFile("AddStamp.docx", FileFormat.Docx); doc.dispose(); }}

整合所有格式API处理套包Spire.office for Java正在 火热销售中!联系客服立马1分钟了解全部咨询!
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!