【问题标题】:PSPDFKIT instance.addEventListener('annotations.create') is missing the annotation typePSPDFKIT instance.addEventListener('annotations.create') 缺少注释类型
【发布时间】:2021-06-28 08:18:40
【问题描述】:

我正在努力使用 pspdfkit 正确创建和显示我的注释。我想像这样创建我的注释:

 instance.addEventListener("annotations.create", createdAnnotations => {
              const annotation = createdAnnotations
              const serializedObject = toSerializableObject(annotation)
              const annotationsJson = JSON.stringify(serializedObject)
              console.log("clean", JSON.parse(annotationsJson))
              dispatch(createPdfNote(annotationsJson, documentID))
                .then(
                  err => {
                    if (!err) {
                      setSnackContent({
                        severity: "success",
                        message: "Annotation successfully created",
                      })
                    }
                  })
            })

但是在创建注释时缺少注释的类型。

我如何检索它并能够使用 toSerializeObject 来创建我可以在之后重新创建的 JSON?

这是 instance.addEventListener 为我创建的 JSON:

action: null
​​additionalActions: null
​​backgroundColor: null
​​blendMode: "normal"
​​boundingBox: Object { left: 308, top: 118, width: 82, … }
​​createdAt: "2021-06-28T07:58:36.255Z"
​​creatorName: null
​​customData: null
​​hidden: false
​​id: "01F98T156YNAP5N28MAKKQJ2Y4"
​​isCommentThreadRoot: false
​​isDrawnNaturally: false
​​isSignature: false
​​lineWidth: 5
​​lines: Array [ (12) […] ]
​​name: "01F98T156YNAP5N28MAKKQJ2Y4"
​​noPrint: false
​​noRotate: false
​​noView: false
​​noZoom: false
​​note: null
​​opacity: 1
​​pageIndex: 0
​​pdfObjectId: null
​​strokeColor: Object { r: 34, g: 147, b: 251 }
​updatedAt: "2021-06-28T07:58:37.181Z"

不幸的是,我必须通过 pspdfkit 函数toSerializeObject, fromSerializeObject 才能创建并显示注释,但是当我创建它们时它们给我错误unsupported type 和当我尝试重新创建它们时unsupported type change,仅使用 JSON.parse / JSON.stringify 并不能解决问题,并且当用户关闭查看器并重新打开它时,它不会让我使用 instance.create 将创建的注释呈现给 DOM。

【问题讨论】:

    标签: javascript json pspdfkit


    【解决方案1】:

    所以,文档是垃圾,不会撒谎……方法实际上是一个函数,检索到的数组是一个对象等等。

    如何得到我想要的答案是:

                instance.addEventListener("annotations.create", createdNote => {
                  const note = createdNote.get(0)
                  const serializedObjectNote = toSerializableObject(note)
                  const noteJson = JSON.stringify(serializedObjectNote)
                  if (!isLoadingNotes.current) {
                    dispatch(createPdfNote(noteJson, documentID))
                      .then(
                        err => {
                          if (!err) {
                            setSnackContent({
                              severity: "success",
                              message: "Annotation successfully created",
                            })
                          }
                        })
                  }
                })
    

    【讨论】:

      猜你喜欢
      • 2019-09-07
      • 1970-01-01
      • 2019-05-06
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      • 1970-01-01
      • 2010-09-17
      相关资源
      最近更新 更多