Skip to content

Instantly share code, notes, and snippets.

@27sweety
Created May 1, 2019 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 27sweety/7fbfaa010adf5abbd6e37a46ca0d3c5e to your computer and use it in GitHub Desktop.
Save 27sweety/7fbfaa010adf5abbd6e37a46ca0d3c5e 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