// 当前选中的注释
var activeannot;
// 监听 activeAnnotation 事件
pdfui.eventEmitter.on(
PDFViewCtrl.constants.ViewerEvents.activeAnnotation,
async (annotRender) => {
// 1. 获取当前选中的注释
activeannot = annotRender.annot;
var page = activeannot.page;
// 2. 获取当前页所有注释
var annots = await page.getAnnots();
// 3. 获取当前注释的矩形范围(目标区域)
var targetRect = activeannot.getRect();
// 4. 筛选:找出矩形完全落在 targetRect 内的注释
const newList = annots.filter(annot => {
const r = annot.getRect();
// 判断条件(PDF 左下角原点坐标系):
// r.left >= targetRect.left — 左边不超出
// r.right <= targetRect.right — 右边不超出
// r.top <= targetRect.top — 上边不超出
// r.bottom >= targetRect.bottom — 下边不超出
return (
r.left >= targetRect.left &&
r.right <= targetRect.right &&
r.top <= targetRect.top &&
r.bottom >= targetRect.bottom
);
});
console.log("压盖的注释列表:", newList);
}
);