PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
ComPDF React Native SDK支持通过api删除选定的注释,删除注释步骤如下:
获取文档对象
获取需要删除注释的页面对象。
获取该页面的注释列表。
在注释列表中寻找想要删除的注释。
删除该注释。
示例代码:
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() 方法删除当前文档中的所有注释。
示例代码:
const pdfReaderRef = useRef<CPDFReaderView>(null);
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={ComPDFKit.getDefaultConfig({
})}/>
const removeResult = await pdfReaderRef.current?.removeAllAnnotations();注意:此方法不会删除超链接注释。