Skip to content
ComPDF
Guides

大纲

大纲是 PDF 文档的结构化导航工具,通常显示在文档阅读器的侧边栏或面板中。它可以基于文档中的标题和章节信息自动生成,也可以手动编辑和调整。大纲以层次结构的方式展示文档内容,帮助用户快速定位和浏览,实现文档不同部分之间的便捷导航。

获取大纲

tsx
const outlineRoot = await pdfReaderRef?.current?._pdfDocument.getOutlineRoot();

新增大纲

tsx
const outlineRoot = await pdfReaderRef?.current?._pdfDocument.getOutlineRoot();
if (outlineRoot == null){
  outlineRoot = await pdfReaderRef?.current?._pdfDocument.newOutlineRoot();
}

const result = await pdfReaderRef?.current?._pdfDocument.addOutline(
     outlineRoot.uuid,
     title: 'New Outline',
     insertIndex: 0,
     pageIndex: 0
   );

编辑大纲

tsx
await pdfReaderRef.current?._pdfDocument.updateOutline(outline.uuid, 'Chapter 1', pageIndex);

删除大纲

tsx
await pdfReaderRef.current?._pdfDocument.removeOutline(outline.uuid);

移动大纲

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

tsx
const result = await pdfReaderRef.current?._pdfDocument.moveOutline(
  outlineToMove,          // 需要移动的大纲节点
  targetParentOutline,    // 新的父节点。移动完成后,outline 将作为其子节点存在
  0                       // 在父节点的子节点列表中的插入位置,-1 表示追加到末尾
);