添加题注,设置在顶部

显示效果:

示例代码所生成的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 iofd.layout.contants.VerticalAlignmentType;

import java.io.File;

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

/**
 * 添加图片的示例,添加题注,并且设置题注显示在图片顶部
 * */
public class C0305ImageAddNoteTop {

	public static void main(String[] args) throws Throwable {
		C0305ImageAddNoteTop o = new C0305ImageAddNoteTop();
		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("图", "测试在图片顶部显示题注");
		/*
		 * 设置在图片顶部显示题注
		 * */
		note.setVerticalAlignType(VerticalAlignmentType.TOP);
		image.setNote(note);
		doc.add(image);
		
		String fileName = TestDocUtil.getOfdFilePath(this.getClass());
		doc.save(fileName);
		System.out.println(clzName + " end");
	}
}