设置限制目录层级

显示效果:

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

 示例代码

package test.create.c10;

import iofd.layout.DefaultPageProperty;
import iofd.layout.OfdDocument;
import iofd.layout.block.PageSeparator;
import iofd.layout.block.Paragraph;
import iofd.layout.block.paragraph.Text;
import iofd.layout.physcial.page.menu.MenuCreator;
import test.create.TestDocUtil;

public class C1004CustomizeMultLevelMenuWithFrontCover {

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

	private void done() throws Throwable {
		String clzName = this.getClass().getSimpleName();
		System.out.println(clzName + " begin");
		OfdDocument doc = new OfdDocument();
		DefaultPageProperty prop = DefaultPageProperty.createDefaultPageProperty();
		prop.setDebug(true);
		doc.setDefaultPageProperty(prop);
		doc.setSetFrontCoverPage(true);
		MenuCreator menuCreator = new MenuCreator("Index");
		menuCreator.setMaxPaintLevel(3);
		doc.setMenuCreator(menuCreator);
		
		Paragraph p = new Paragraph();
		String s = "该文本展示如何设置多级目录,并且带封面[本页为封面],这里自定义了目录列表的显示层级为三层,注意观察目录显示内容和阅读器左侧显示内容的层级是不一样的";
		p.add(new Text(s));
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "1  测试目录第1级";
		p.add(new Text(s));
		p.createCurrentLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "1.1  测试目录第2级";
		p.add(new Text(s));
		p.createSubLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "1.1.1  测试目录第3级";
		p.add(new Text(s));
		p.createSubLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "1.1.1.1  测试目录第4级";
		p.add(new Text(s));
		p.createSubLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "1.1.2  测试目录第3级";
		p.add(new Text(s));
		p.createManualMenuInfo(null, s, 3);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "1.1.2.1  测试目录第4级";
		p.add(new Text(s));
		p.createSubLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "1.1.2.2  测试目录第4级";
		p.add(new Text(s));
		p.createCurrentLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "2  测试目录第1级";
		p.add(new Text(s));
		p.createManualMenuInfo(null, s, 1);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "2.1  测试目录第2级";
		p.add(new Text(s));
		p.createSubLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "2.1.1  测试目录第3级";
		p.add(new Text(s));
		p.createSubLevelMenuInfo(null, s);
		doc.add(p);
		
		doc.add(new PageSeparator());
		
		p = new Paragraph();
		s = "2.1.1.1  测试目录第4级";
		p.add(new Text(s));
		p.createSubLevelMenuInfo(null, s);
		doc.add(p);

		String fileName = TestDocUtil.getOfdFilePath(this.getClass());
		doc.save(fileName);
		System.out.println(clzName + " end");
	}
}