Hinzufügen von Beschriftungen mit schreibgeschütztem PSPDF Kit-Textformularfeld. Statische PSPDF-Kit-Instanz erstellt.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
class Annotation {
|
||||
static async createAnnotations(document) {
|
||||
static async createAnnotations(document, instance) {
|
||||
const signatures = []
|
||||
|
||||
for(var element of document.elements){
|
||||
const [annotation, formField, annotation_date, formFieldDate, annotation_postcode, formFieldPostcode, annotation_city, formFieldCity] = await Annotation.createSignature(element)
|
||||
for (var element of document.elements) {
|
||||
const [annotation, formField, annotation_date, formFieldDate, annotation_postcode, formFieldPostcode, annotation_city, formFieldCity, annotation_date_label, formFieldDateLabel, annotation_postcode_label, formFieldPostcodeLabel, annotation_city_label, formFieldCityLabel] = await Annotation.createSignature(element)
|
||||
signatures.push(annotation)
|
||||
signatures.push(formField)
|
||||
signatures.push(annotation_date)
|
||||
@@ -12,9 +12,18 @@
|
||||
signatures.push(formFieldPostcode)
|
||||
signatures.push(annotation_city)
|
||||
signatures.push(formFieldCity)
|
||||
|
||||
signatures.push(annotation_date_label)
|
||||
signatures.push(formFieldDateLabel)
|
||||
|
||||
signatures.push(annotation_postcode_label)
|
||||
signatures.push(formFieldPostcodeLabel)
|
||||
|
||||
signatures.push(annotation_city_label)
|
||||
signatures.push(formFieldCityLabel)
|
||||
}
|
||||
|
||||
return [...signatures ]
|
||||
await instance.create(signatures)
|
||||
}
|
||||
|
||||
static async createSignature(element) {
|
||||
@@ -45,6 +54,10 @@
|
||||
annotationIds: PSPDFKit.Immutable.List([annotation.id]),
|
||||
})
|
||||
|
||||
/**
|
||||
* Date, post code and place text form part
|
||||
*/
|
||||
const date_place_top_shift = 16
|
||||
//date
|
||||
const id_date = PSPDFKit.generateInstantId()
|
||||
const annotation_date = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
@@ -56,17 +69,17 @@
|
||||
boundingBox: new PSPDFKit.Geometry.Rect({
|
||||
width: width * 0.75,
|
||||
height: height / 2,
|
||||
top: top + height + 25,
|
||||
top: top + height + 25 + date_place_top_shift,
|
||||
left: left - width * .25,
|
||||
}),
|
||||
fontSize:8,
|
||||
fontSize: 8,
|
||||
additionalActions: {
|
||||
onFormat: new PSPDFKit.Actions.JavaScriptAction({
|
||||
script: `AFDate_FormatEx("dd/mm/yyyy")`,
|
||||
}),
|
||||
onFormat: new PSPDFKit.Actions.JavaScriptAction({
|
||||
script: `AFDate_FormatEx("dd/mm/yyyy")`,
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const formFieldDate = new PSPDFKit.FormFields.TextFormField({
|
||||
name: id_date,
|
||||
annotationIds: PSPDFKit.Immutable.List([annotation_date.id]),
|
||||
@@ -85,12 +98,12 @@
|
||||
boundingBox: new PSPDFKit.Geometry.Rect({
|
||||
width: width * 0.45,
|
||||
height: height / 2,
|
||||
top: top + height + 25,
|
||||
top: top + height + 25 + date_place_top_shift,
|
||||
left: left - width * .25 + width * 0.80,
|
||||
}),
|
||||
fontSize:8
|
||||
fontSize: 8
|
||||
})
|
||||
|
||||
|
||||
const formFieldPostcode = new PSPDFKit.FormFields.TextFormField({
|
||||
name: id_postcode,
|
||||
annotationIds: PSPDFKit.Immutable.List([annotation_postcode.id]),
|
||||
@@ -109,19 +122,104 @@
|
||||
boundingBox: new PSPDFKit.Geometry.Rect({
|
||||
width: width * 0.75,
|
||||
height: height / 2,
|
||||
top: top + height + 25,
|
||||
top: top + height + 25 + date_place_top_shift,
|
||||
left: left - width * .25 + width * 1.30,
|
||||
}),
|
||||
fontSize:8
|
||||
fontSize: 8
|
||||
})
|
||||
|
||||
|
||||
const formFieldCity = new PSPDFKit.FormFields.TextFormField({
|
||||
name: id_city,
|
||||
annotationIds: PSPDFKit.Immutable.List([annotation_city.id]),
|
||||
value: location.city
|
||||
value: location.city,
|
||||
})
|
||||
|
||||
return [annotation, formField, annotation_date, formFieldDate, annotation_postcode, formFieldPostcode, annotation_city, formFieldCity]
|
||||
/**
|
||||
* Date, post code and place label part
|
||||
*/
|
||||
const label_top_shift = -15
|
||||
|
||||
//date label
|
||||
const id_date_label = PSPDFKit.generateInstantId()
|
||||
const annotation_date_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_date_label,
|
||||
pageIndex: page,
|
||||
formFieldName: id_date_label,
|
||||
blendMode: 'multiply',
|
||||
boundingBox: new PSPDFKit.Geometry.Rect({
|
||||
width: width * 0.75,
|
||||
height: height / 2,
|
||||
top: top + height + 25 + label_top_shift + date_place_top_shift,
|
||||
left: left - width * .25,
|
||||
}),
|
||||
fontSize: 8,
|
||||
backgroundColor: PSPDFKit.Color.TRANSPARENT,
|
||||
fontColor: PSPDFKit.Color.Black,
|
||||
isBold: true,
|
||||
required: true
|
||||
})
|
||||
|
||||
const formFieldDateLabel = new PSPDFKit.FormFields.TextFormField({
|
||||
name: id_date_label,
|
||||
annotationIds: PSPDFKit.Immutable.List([annotation_date_label.id]),
|
||||
value: "Date",
|
||||
readOnly: true
|
||||
})
|
||||
|
||||
//postcode label
|
||||
const id_postcode_label = PSPDFKit.generateInstantId()
|
||||
const annotation_postcode_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_postcode_label,
|
||||
pageIndex: page,
|
||||
formFieldName: id_postcode_label,
|
||||
blendMode: 'multiply',
|
||||
boundingBox: new PSPDFKit.Geometry.Rect({
|
||||
width: width * 0.45,
|
||||
height: height / 2,
|
||||
top: top + height + 25 + label_top_shift + date_place_top_shift,
|
||||
left: left - width * .25 + width * 0.80,
|
||||
}),
|
||||
fontSize: 8,
|
||||
backgroundColor: PSPDFKit.Color.TRANSPARENT,
|
||||
fontColor: PSPDFKit.Color.Black,
|
||||
isBold: true,
|
||||
required: true
|
||||
})
|
||||
|
||||
const formFieldPostcodeLabel = new PSPDFKit.FormFields.TextFormField({
|
||||
name: id_postcode_label,
|
||||
annotationIds: PSPDFKit.Immutable.List([annotation_postcode_label.id]),
|
||||
value: "PLZ",
|
||||
readOnly: true
|
||||
})
|
||||
|
||||
//city label
|
||||
const id_city_label = PSPDFKit.generateInstantId()
|
||||
const annotation_city_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_city_label,
|
||||
pageIndex: page,
|
||||
formFieldName: id_city_label,
|
||||
blendMode: 'multiply',
|
||||
boundingBox: new PSPDFKit.Geometry.Rect({
|
||||
width: width * 0.75,
|
||||
height: height / 2,
|
||||
top: top + height + 25 + label_top_shift + date_place_top_shift,
|
||||
left: left - width * .25 + width * 1.30,
|
||||
}),
|
||||
fontSize: 8,
|
||||
backgroundColor: PSPDFKit.Color.TRANSPARENT,
|
||||
fontColor: PSPDFKit.Color.Black,
|
||||
isBold: true,
|
||||
})
|
||||
|
||||
const formFieldCityLabel = new PSPDFKit.FormFields.TextFormField({
|
||||
name: id_city_label,
|
||||
annotationIds: PSPDFKit.Immutable.List([annotation_city_label.id]),
|
||||
value: "Ort",
|
||||
readOnly: true
|
||||
})
|
||||
|
||||
return [annotation, formField, annotation_date, formFieldDate, annotation_postcode, formFieldPostcode, annotation_city, formFieldCity, annotation_date_label, formFieldDateLabel, annotation_postcode_label, formFieldPostcodeLabel, annotation_city_label, formFieldCityLabel]
|
||||
}
|
||||
|
||||
static createTextBox(element) {
|
||||
@@ -176,7 +274,7 @@
|
||||
const pageAnnotations = allAnnotations.filter(Annotation.isSignature)
|
||||
//deleting all Annotations
|
||||
return await instance.delete(pageAnnotations)
|
||||
}
|
||||
}
|
||||
|
||||
static async validateAnnotations(instance) {
|
||||
const allAnnotations = await Annotation.getAnnotations(instance)
|
||||
@@ -211,7 +309,7 @@
|
||||
const canvas = document.createElement('canvas')
|
||||
const scale = 4
|
||||
const fontSize = 10
|
||||
|
||||
|
||||
canvas.width = width * scale
|
||||
canvas.height = height * scale
|
||||
|
||||
|
||||
Reference in New Issue
Block a user