我正在努力使用 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。