Skip to content
ComPDF
Guides

书签

书签是 PDF 文档中的一种便捷导航工具,允许用户快速跳转到文档中的特定页面或位置。书签通常显示在文档阅读器的侧边栏或面板中,用户可以通过点击书签快速访问相关内容。书签可以手动添加,也可以基于文档结构自动生成。

获取书签

tsx
const bookmarks = await pdfReaderRef.current?._pdfDocument.getBookmarks();

新增书签

tsx
const title = 'Chapter 1';
const pageIndex = 2;
const addResult = await pdfReaderRef.current?._pdfDocument.addBookmark(title, pageIndex);

编辑书签

tsx
const bookmarks = await pdfReaderRef.current?._pdfDocument.getBookmarks();
if (bookmarks.length > 0) {
  const bookmark = bookmarks[0];
  bookmark.setTitle('Updated Title');
  const updateResult = await pdfReaderRef.current?._pdfDocument.updateBookmark(bookmark);
}

删除书签

tsx
const pageIndex = 0;
const removeResult = await pdfReaderRef.current?._pdfDocument.removeBookmark(pageIndex);

判断书签是否存在

tsx
const pageIndex = 0;
const hasBookmark = await pdfReaderRef.current?._pdfDocument.hasBookmark(pageIndex);