{"id":7056,"date":"2025-10-29T17:03:48","date_gmt":"2025-10-29T09:03:48","guid":{"rendered":"https:\/\/support.fuxinsoft.cn\/?p=7056"},"modified":"2026-04-16T09:37:54","modified_gmt":"2026-04-16T01:37:54","slug":"websdk%e4%b8%ad%e5%a6%82%e4%bd%95%e6%8a%8a%e5%a4%9a%e4%b8%aa%e6%b3%a8%e9%87%8a%e7%bb%84%e5%90%88","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=7056","title":{"rendered":"WebSDK \u5b9e\u73b0\u6ce8\u91ca\u7ec4\u5408\u4e0e\u53d6\u6d88\u7ec4\u5408"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728WebSDK\u4e2d\u591a\u4e2a\u6ce8\u91ca\u9700\u8981\u7ec4\u5408\uff0c11.1\u7248\u672c\u524d\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\uff0c11.1\u540e\u7684\u7248\u672c\u53ef\u76f4\u63a5\u4f7f\u7528setannotgroup<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. \u901a\u8fc7\u76d1\u542c\u4e8b\u4ef6\u83b7\u53d6\u5f53\u524d\u662f\u5426\u6709\u591a\u4e2a\u9009\u4e2d\u7684\u6ce8\u91ca<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5168\u5c40\u53d8\u91cf\u8bb0\u5f55\u9009\u4e2d\u7684\u6ce8\u91ca\n        var annotsActive = &#091;];\n\n\/\/\u6dfb\u52a0\u76d1\u542c\u5224\u65ad\u9009\u4e2d\u7684\u6ce8\u91ca\n        pdfui.eventEmitter.on(PDFViewCtrl.constants.ViewerEvents.activeAnnotation, (annotRender) =&gt; {\n            console.log('activeAnnotation',annotRender)\n            const isExist = annotsActive.some(item =&gt; item.id === annotRender.annot.id);\n            if (isExist) {\n                return;\n            }\n            var annotJson = {\n                type: annotRender.annot.getType(),\n                rect:annotRender.annot.getRect(),\n                borderStyle: {\n                    width: annotRender.annot.getBorderWidth(), \/\/ \u8fb9\u6846\u5bbd\u5ea6\n                    style: annotRender.annot.getBorderStyle(), \/\/ \u8fb9\u6846\u6837\u5f0f\n                    color: annotRender.annot.getBorderColor() \/\/ \u8fb9\u6846\u989c\u8272 \n                },\n            };\n            annotsActive.push({ id: annotRender.annot.id, annotJson: annotJson,pageindex: annotRender.annot.page.getIndex() ,annot:annotRender.annot});\n        })\n\n\/\/\u6dfb\u52a0\u76d1\u542c\u5224\u65ad\u53d6\u6d88\u9009\u4e2d\u7684\u6ce8\u91ca\n        pdfui.eventEmitter.on(PDFViewCtrl.constants.ViewerEvents.unActiveAnnotation, (annotRender) =&gt; {\n            console.log('unActiveAnnotation',annotRender)\n            const index = annotsActive.findIndex(item =&gt; item.id === annotRender.annot.id);\n            if (index!== -1) {\n                annotsActive.splice(index, 1);\n            }\n        });\n\n\/\/\u591a\u9009\u76d1\u542c\u4e8b\u4ef6\n        pdfui.eventEmitter.on(PDFViewCtrl.constants.ViewerEvents.activeMultipleAnnotations, (annotRenders) =&gt; {\n            console.log('activeMultipleAnnotations',annotRenders)\n            annotRenders.forEach(annotRender =&gt; {\n                if (!annotsActive.some(item =&gt; item.id === annotRender.annot.id)) {\n                    \/\/ \u82e5\u7ed3\u6784\u4e0d\u540c\uff0c\u9700\u8f6c\u6362\u4e3a annotsActive \u6240\u9700\u7684\u7c7b\u578b\uff08\u6b64\u5904\u5047\u8bbe\u7ed3\u6784\u517c\u5bb9\uff09\n                    \n                    var annotJson = {\n                        type: annotRender.annot.getType(),\n                        rect:annotRender.annot.getRect(),\n                        borderStyle: {\n                            width: annotRender.annot.getBorderWidth(), \/\/ \u8fb9\u6846\u5bbd\u5ea6\n                            style: annotRender.annot.getBorderStyle(), \/\/ \u8fb9\u6846\u6837\u5f0f\n                            color: annotRender.annot.getBorderColor() \/\/ \u8fb9\u6846\u989c\u8272 \n                        },\n                    };\n                    annotsActive.push({ id: annotRender.annot.id, annotJson: annotJson ,pageindex: annotRender.annot.page.getIndex(),annot:annotRender.annot});\n                }\n            });\n        })\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. \u7ec4\u5408\u6ce8\u91ca\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>async function \u7ec4\u5408\u6ce8\u91ca(){\n            if(annotsActive.length === 0){\n                return;\n            }\n\n            var pdfviewer = await pdfui.getPDFViewer();\n            var pdfdoc = await pdfviewer.getCurrentPDFDoc();\n            var page = await pdfdoc.getPageByIndex(annotsActive&#091;0].pageindex);\n            \/\/\u8981\u662fpage\u4e0d\u4e00\u6837\uff0c\u63d0\u793a\u5f53\u524d\u9009\u4e2d\u7684\u7ec4\u5408\u4e0d\u5728\u4e00\u4e2a\u9875\u9762\uff0c\u91cd\u65b0\u9009\u62e9\uff1f\n            if(annotsActive.some(item =&gt; item.pageindex !== annotsActive&#091;0].pageindex)){\n                alert('\u5f53\u524d\u9009\u4e2d\u7684\u7ec4\u5408\u4e0d\u5728\u4e00\u4e2a\u9875\u9762\uff0c\u91cd\u65b0\u9009\u62e9\uff1f');\n                return;\n            }\n\n            const allAnnots = annotsActive.map(item =&gt; item.annotJson);\n            await page.addAnnotGroup(allAnnots,1)\n\n            const allAnnotsId = annotsActive.map(item =&gt; item.id);\n            for (const id of allAnnotsId) {\n                \/\/ \u7b49\u5f85\u5f53\u524d\u6807\u6ce8\u5220\u9664\u5b8c\u6210\u540e\uff0c\u518d\u5904\u7406\u4e0b\u4e00\u4e2a\n                await page.removeAnnotByObjectNumber(id);\n            }\n        }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. \u53d6\u6d88\u7ec4\u5408\u6ce8\u91ca\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>async function \u53d6\u6d88\u6ce8\u91ca(){\n            if(annotsActive.length != 1 || annotsActive&#091;0].annot.groupElements.length === 0){\n                return;\n            }\n            \n            var pdfviewer = await pdfui.getPDFViewer();\n            var pdfdoc = await pdfviewer.getCurrentPDFDoc();\n            var page = await pdfdoc.getPageByIndex(annotsActive&#091;0].pageindex);\n\n            \/\/\u6839\u636eannotsActive&#091;0].annot.groupElements\u5220\u9664\u91cc\u9762\u5177\u4f53\u7684\u5185\u5bb9\n            for(const item of annotsActive&#091;0].annot.groupElements)\n            {\n                var annotJson = {\n                        type: item.getType(),\n                        rect: item.getRect(),\n                        borderStyle: {\n                            width: item.getBorderWidth(), \/\/ \u8fb9\u6846\u5bbd\u5ea6\n                            style: item.getBorderStyle(), \/\/ \u8fb9\u6846\u6837\u5f0f\n                            color: item.getBorderColor() \/\/ \u8fb9\u6846\u989c\u8272 \n                        },\n                    };\n                await page.addAnnot(annotJson);\n            }\n\n            await page.removeAnnotByObjectNumber(annotsActive&#091;0].id)\n        }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728WebSDK\u4e2d\u591a\u4e2a\u6ce8\u91ca\u9700\u8981\u7ec4\u5408\uff0c11.1\u7248\u672c\u524d\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\uff0c11.1\u540e\u7684\u7248\u672c\u53ef\u76f4\u63a5\u4f7f\u7528setanno [&hellip;]<\/p>\n","protected":false},"author":33,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[595,1173,374,664,1122],"class_list":["post-7056","post","type-post","status-publish","format-standard","hentry","category-websdk","tag-websdk","tag-1173","tag-374","tag-664","tag-1122"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","_links":{"self":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7056"}],"version-history":[{"count":4,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7056\/revisions"}],"predecessor-version":[{"id":8460,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7056\/revisions\/8460"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}