Skip to content

Instantly share code, notes, and snippets.

@karagraysen
Forked from 27sweety/checkbox.js
Created May 3, 2019 11:46
Show Gist options
  • Save karagraysen/31c100cc6277d810c5a647127eb9c92b to your computer and use it in GitHub Desktop.
Save karagraysen/31c100cc6277d810c5a647127eb9c92b to your computer and use it in GitHub Desktop.
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