添加题注

显示效果:

示例代码所生成的OFD文件:下载

 示例代码

package test.create.c03;


import iofd.layout.OfdDocument;
import iofd.layout.block.OfdImage;
import iofd.layout.block.Paragraph;
import iofd.layout.block.paragraph.Note;

import java.io.File;

import test.create.TestDocUtil;
import test.create.resource.TestFileResource;

/**
 * 添加图片的示例,添加题注
 * */
public class C0304ImageAddNote {

	public static void main(String[] args) throws Throwable {
		C0304ImageAddNote o = new C0304ImageAddNote();
		o.done();
	}

	private void done() throws Throwable {
		String clzName = this.getClass().getSimpleName();
		System.out.println(clzName + " begin");
		
		OfdDocument doc = new OfdDocument();
		
		String s = "这是一个插入图片的示例,添加题注。";
		Paragraph p = new Paragraph();
		p.add(s);
		doc.add(p);
		
		File imageFile = new File(TestFileResource.class.getResource("400X300px2.jpg").toURI());
		OfdImage image = new OfdImage(imageFile);
		/*
		 * 添加题注
		 * */
		Note note = new Note("图", "测试题注");
		image.setNote(note);
		doc.add(image);
		
		String fileName = TestDocUtil.getOfdFilePath(this.getClass());
		doc.save(fileName);
		System.out.println(clzName + " end");
	}
}