-
-
Save karagraysen/31c100cc6277d810c5a647127eb9c92b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insertCheckboxFormField(pageRect, pageNo, type) { | |
let instance = this.PSPDF; | |
async function createNewFormField(instance) { | |
try { | |
const formFieldName = type + "_formfield"; | |
const newFormFieldName = `${formFieldName}_${Math.random() | |
.toString(36) | |
.replace(/[^a-z]+/g, "")}`; | |
const annotation = await instance.createAnnotation( | |
new PSPDFKit.Annotations.WidgetAnnotation({ | |
formFieldName: newFormFieldName, | |
pageIndex: pageNo, | |
boundingBox: pageRect, | |
opacity: 0, | |
borderWidth: 0, | |
borderColor: new PSPDFKit.Color({ r: 255, g: 165, b: 0 }) | |
//backgroundColor: new PSPDFKit.Color({ r: 255, g: 165, b: 0 }) | |
}) | |
); | |
const formField = await instance.createFormField( | |
new PSPDFKit.FormFields.CheckBoxFormField({ | |
name: newFormFieldName, | |
annotationIds: new PSPDFKit.Immutable.List([annotation.id]), | |
options: new PSPDFKit.Immutable.List([ | |
new PSPDFKit.FormOption({ | |
label: "on", | |
value: "on" | |
}), | |
new PSPDFKit.FormOption({ | |
label: "off", | |
value: "off" | |
}) | |
]) | |
}) | |
); | |
PubSub.publish('ANNOTATION_SELECTED',annotation); | |
setTimeout(() => {instance.setSelectedAnnotation(annotation)},200) | |
//instance.setSelectedAnnotation(annotation); | |
return formField; | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
createNewFormField(instance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment