删除注释
ComPDFKit ReactNative SDK支持通过api删除选定的注释,删除注释步骤如下:
获取文档对象
获取需要删除注释的页面对象。
获取该页面的注释列表。
在注释列表中寻找想要删除的注释。
删除该注释。
示例代码:
tsx
const pdfReaderRef = useRef<CPDFReaderView>(null);
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={ComPDFKit.getDefaultConfig({
})}/>
// 获取对应页码的页面对象
const page = pdfReaderRef?.current?._pdfDocument.pageAtIndex(0);
// 获取该页面上的所有注释
const annotations = await page?.getAnnotations();
if(annotations[0]){
await page.removeAnnotation(annotations[0]);
}
// 或使用
pdfReaderRef?.current?._pdfDocument.removeAnnotation(annotations[0]);
或者您可以通过调用 removeAllAnnotations()
方法删除当前文档中的所有注释。
- 返回值是一个布尔值,表示操作是否成功。
示例代码:
tsx
const pdfReaderRef = useRef<CPDFReaderView>(null);
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={ComPDFKit.getDefaultConfig({
})}/>
const removeResult = await pdfReaderRef.current?.removeAllAnnotations();
注意:此方法不会删除超链接注释。