@@ -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