Skip to content
ComPDF
Guides

大纲

大纲是 PDF 文档的结构化导航工具,通常显示在文档阅读器的侧边栏或面板上,它通常基于文档中的标题和章节信息自动生成,也可以手动编辑和调整。大纲提供了文档的层次结构,使用户能够更容易地定位和浏览内容,同时可以使用大纲快速导航到文档的不同部分。

展示大纲

dart
CPDFOutline? rootOutline = await document.getOutlineRoot();

新增大纲

dart
CPDFOutline? rootOutline = await document.getOutlineRoot();
if (rootOutline == null){
  rootOutline = await document.newOutlineRoot();
}

bool result = await document.addOutline(
     parentUuid: rootOutline.uuid,
     insertIndex: 0,
     title: 'New Outline',
     pageIndex: 0
   );

编辑大纲

dart
  bool result = await document.updateOutline(
    uuid: outline.uuid,
    title: 'Updated Title',
    pageIndex: 1
  );

删除大纲

dart
bool result = await document.removeOutline(outline.uuid);

移动大纲

moveOutline 用于在文档的大纲树(Outline Tree)中重新定位某个已有的大纲节点。该方法会将目标节点移动到新的父节点 newParent 下,并按照 insertIndex 指定的位置插入,从而实现变更层级关系与调整同级顺序。

dart
bool result = await document.moveOutline(
  outline: outlineToMove,					// 需要移动的大纲节点(待移动的目标节点)
  newParent: targetParentOutline, // 新的父节点。移动完成后,outline 将作为 newParent 的子节点存在
  insertIndex: 0,									// 在 newParent 的子节点列表中的插入位置, -1表示追加到末尾
);