pdfui.eventEmitter.on(UIExtension.PDFViewCtrl.PDF.constant.DataEvents.annotationAdded, async (annotations) => {
console.log(annotations, "annotationAdded");
var theAnnot = annotations[0];
if (theAnnot.info.type == "highlight") {
var curPageRender = await pdfui.getPDFPageRender(theAnnot.page.info.index);
//将指定区域的矩形坐标值 转换为 设备坐标形式
var devRect = theAnnot.page.getDeviceRect(theAnnot.info.rect, curPageRender.scale, curPageRender.rotate);
console.log(devRect);
curPageRender.getSnapshot(devRect.left, devRect.top, devRect.right - devRect.left, devRect.bottom - devRect.top).then(imageBlob => {
// 获取到图片流。
console.log(imageBlob);
//下载图片
const url = URL.createObjectURL(imageBlob);
console.log(url);
let link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute('download', "test");
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href); // 释放URL 对象
document.body.removeChild(link);
});
}
})