gpt4 book ai didi

javascript - importAnnotCommand 返回未定义

转载 作者:行者123 更新时间:2023-11-30 06:15:46 25 4
gpt4 key购买 nike

我正在尝试使用 xfdf 格式和 importAnnotCommand() 方法导入手绘注释,但有时我得到未定义的返回值,我正在使用 getAnnotCommand() 方法生成这些字符串。

xfdf 字符串由 getAnnotCommand() 方法生成,我将该字符串记录到控制台,以确保它看起来正确。注释仅可靠地加载在文档的前两页上。

导入代码,backlog中包含加载失败的注解:

        const  backlog = docModel.prototype.annots[webviewer.id].backlog
const backup = docModel.prototype.annots[webviewer.id].backup
let annots = annotationManager.importAnnotations(backup)
annotationManager.drawAnnotationsFromList(annots)
let tmp = [];
if (Array.isArray(backlog)) {
while(backlog.length > 0) {
const backlogObj = backlog.pop()
if (backlogObj.xfdf) {
const xfdf = backlogObj.xfdf
const annot = annotationManager.importAnnotCommand(xfdf)[0]
if (annot === undefined) {
tmp.push(backlogObj)
} else {
}
console.log('loading annot:',annot,'\nxfdf:',xfdf)
} else if(backlogObj.hide) {
annotationManager.hideAnnotation(annotationManager.getAnnotationById(backlogObj.id))
}
}
docModel.prototype.annots[webviewer.id].backlog = tmp

失败的 xfdf 示例:

<?xml version="1.0" encoding="UTF-8" ?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields />
<add><ink page="1" rect="302.917853,630.040373,348.65741,715.919953" color="#D5252E" flags="print" name="00d08e8b-01b7-e6d2-2f88-35890f19f16c" title="Guest" subject="Free hand" date="D:20190522154716-04'00'" width="4.2" creationdate="D:20190522154714-04'00'"><inklist><gesture>317.39,711.72;317.39,711.72;317.39,711.72;317.39,711.72;318.32,711.72;320.19,711.72;322.05,711.72;323.92,711.72;325.79,711.72;327.65,710.79;328.59,710.79;329.52,710.79;330.46,709.85;331.39,708.92;332.32,707.05;333.26,704.25;334.19,701.45;334.19,698.65;334.19,694.92;334.19,692.12;333.26,688.38;331.39,685.58;329.52,682.78;328.59,679.98;325.79,675.31;322.05,671.58;318.32,666.91;314.59,661.31;311.79,656.64;309.92,653.84;308.05,650.11;308.05,647.31;307.12,644.51;307.12,642.64;308.05,640.77;308.05,639.84;308.98,638.91;309.92,637.97;310.85,637.04;312.72,636.11;315.52,635.17;318.32,635.17;322.99,634.24;327.65,634.24;331.39,634.24;335.12,634.24;337.92,634.24;341.66,634.24;343.52,634.24;344.46,634.24;344.46,634.24</gesture></inklist></ink></add>
<modify />
<delete />
</xfdf>

有效的 xfdf 示例:

?xml version="1.0" encoding="UTF-8" ?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields />
<add><ink page="0" rect="325.321587,653.377596,335.588565,746.725088" color="#D5252E" flags="print" name="849c13ac-c0e6-e639-8d50-0c6b6639a3e2" title="Guest" subject="Free hand" date="D:20190522154712-04'00'" width="4.2" creationdate="D:20190522154710-04'00'"><inklist><gesture>329.52,742.53;330.46,742.53;330.46,741.59;330.46,739.72;330.46,737.86;330.46,733.19;330.46,726.66;331.39,717.32;331.39,707.99;331.39,698.65;331.39,692.12;331.39,674.38;331.39,667.85;331.39,663.18;331.39,661.31;331.39,659.44;331.39,658.51;331.39,657.58;331.39,657.58</gesture></inklist></ink></add>
<modify />
<delete />
</xfdf>

以下是我收到的错误消息,但每次返回 undefined 时它都不会消失

CoreControls.js:989 exportAnnotations was called before all annotations were loaded.
Gq @ CoreControls.js:989
(anonymous) @ CoreControls.js:1479
Promise.then (async)
(anonymous) @ CoreControls.js:1479
dispatch @ jquery-3.2.1.min.js:3
q.handle @ jquery-3.2.1.min.js:3
trigger @ jquery-3.2.1.min.js:4
triggerHandler @ jquery-3.2.1.min.js:4
applyWithArgs @ CoreControls.js:92
trigger @ CoreControls.js:92
Tg @ CoreControls.js:978
HE @ CoreControls.js:1014
Yw @ CoreControls.js:1012
uo @ CoreControls.js:1011
uo @ CoreControls.js:990
updateAnnotList @ my_file.js:224

请注意,我代码中的第 224 行是 const annot = annotationManager.importAnnotCommand(xfdf)[0] 来自上面

我希望 importAnnotCommand(xfdf) 会返回导入的注释列表,但有时它会失败,只会返回未定义的。

最佳答案

CoreControls.js:989 exportAnnotations was called before all annotations were loaded.

看来您正在尝试导出到 soon。初始加载文档后加载注释,如果有很多,可能需要一段时间。

您想等待这个事件。

https://www.pdftron.com/documentation/web/guides/annotation-events#annotationsloaded

不过,在对文档进行任何操作之前,您需要等待 documentLoaded 事件。

https://www.pdftron.com/documentation/web/guides/webviewer-events/#documentviewerdocumentloaded

关于javascript - importAnnotCommand 返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56278983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com