Entwicklung von Methoden zur Datums- und Ortserkennung. Fügen Sie "annotations" hinzu, damit der Benutzer das Datum und die Ortsangaben bei Bedarf aktualisieren kann.
This commit is contained in:
parent
408969d6dd
commit
c0cece62af
@ -1,25 +1,27 @@
|
|||||||
class Annotation {
|
class Annotation {
|
||||||
static createAnnotations(document) {
|
static async createAnnotations(document) {
|
||||||
const signatures = []
|
const signatures = []
|
||||||
document.elements.forEach((element) => {
|
|
||||||
const [annotation, formField] = Annotation.createSignature(element)
|
for(var element of document.elements){
|
||||||
|
const [annotation, formField, annotation2, formFieldDate] = await Annotation.createSignature(element)
|
||||||
signatures.push(annotation)
|
signatures.push(annotation)
|
||||||
signatures.push(formField)
|
signatures.push(formField)
|
||||||
})
|
signatures.push(annotation2)
|
||||||
|
signatures.push(formFieldDate)
|
||||||
return {
|
|
||||||
signatures: signatures
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [...signatures ]
|
||||||
}
|
}
|
||||||
|
|
||||||
static createSignature(element) {
|
static async createSignature(element) {
|
||||||
const id = PSPDFKit.generateInstantId()
|
const id = PSPDFKit.generateInstantId()
|
||||||
const width = Annotation.inchToPoint(element.width)
|
const width = Annotation.inchToPoint(element.width)
|
||||||
const height = Annotation.inchToPoint(element.height)
|
const height = Annotation.inchToPoint(element.height)
|
||||||
const top = Annotation.inchToPoint(element.top) - height / 2
|
const top = Annotation.inchToPoint(element.top) - height / 2
|
||||||
const left = Annotation.inchToPoint(element.left) - width / 2
|
const left = Annotation.inchToPoint(element.left) - width / 2
|
||||||
const page = element.page - 1
|
const page = element.page - 1
|
||||||
console.log(id)
|
|
||||||
|
//signatures
|
||||||
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id,
|
id: id,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
@ -39,7 +41,31 @@
|
|||||||
annotationIds: PSPDFKit.Immutable.List([annotation.id]),
|
annotationIds: PSPDFKit.Immutable.List([annotation.id]),
|
||||||
})
|
})
|
||||||
|
|
||||||
return [annotation, formField]
|
//date
|
||||||
|
var city = await getCity();
|
||||||
|
const id_date = PSPDFKit.generateInstantId()
|
||||||
|
const annotation_date = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
|
id: id_date,
|
||||||
|
pageIndex: page,
|
||||||
|
formFieldName: id_date,
|
||||||
|
backgroundColor: PSPDFKit.Color.DarkBlue,
|
||||||
|
blendMode: 'multiply',
|
||||||
|
boundingBox: new PSPDFKit.Geometry.Rect({
|
||||||
|
width: width * 1.5,
|
||||||
|
height: height / 2,
|
||||||
|
top: top + height + 10,
|
||||||
|
left: left - width * .25,
|
||||||
|
}),
|
||||||
|
fontSize:8
|
||||||
|
})
|
||||||
|
|
||||||
|
const formFieldDate = new PSPDFKit.FormFields.TextFormField({
|
||||||
|
name: id_date,
|
||||||
|
annotationIds: PSPDFKit.Immutable.List([annotation_date.id]),
|
||||||
|
value: getLocaleDateString() + ", " + city
|
||||||
|
})
|
||||||
|
|
||||||
|
return [annotation, formField, annotation_date, formFieldDate]
|
||||||
}
|
}
|
||||||
|
|
||||||
static createTextBox(element) {
|
static createTextBox(element) {
|
||||||
|
|||||||
@ -70,8 +70,8 @@ class App {
|
|||||||
// Load annotations into PSPDFKit
|
// Load annotations into PSPDFKit
|
||||||
try {
|
try {
|
||||||
this.signatureCount = this.currentDocument.elements.length
|
this.signatureCount = this.currentDocument.elements.length
|
||||||
const annotations = Annotation.createAnnotations(this.currentDocument)
|
const annotations = await Annotation.createAnnotations(this.currentDocument)
|
||||||
await this.Instance.create(annotations.signatures)
|
await this.Instance.create(annotations)
|
||||||
|
|
||||||
const openResponse = await this.Network.openDocument(this.envelopeKey)
|
const openResponse = await this.Network.openDocument(this.envelopeKey)
|
||||||
|
|
||||||
|
|||||||
@ -1 +1,32 @@
|
|||||||
const B64ToBuff = (base64String) => new Uint8Array(Array.from(atob(base64String), char => char.charCodeAt(0))).buffer;
|
const B64ToBuff = (base64String) => new Uint8Array(Array.from(atob(base64String), char => char.charCodeAt(0))).buffer;
|
||||||
|
|
||||||
|
function getCoordinates() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (navigator.geolocation) {
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
position => resolve(position.coords),
|
||||||
|
error => reject(error)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
reject(new Error("Geolocation is not supported by this browser."));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCity() {
|
||||||
|
try {
|
||||||
|
const coords = await getCoordinates();
|
||||||
|
const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`);
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data && data.address) {
|
||||||
|
const city = data.address.city || data.address.town || data.address.village || data.address.hamlet;
|
||||||
|
const postalCode = data.address.postcode;
|
||||||
|
return postalCode + ' ' + city || '';
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLocaleDateString = _ => new Date().toLocaleDateString('de-DE')
|
||||||
Loading…
x
Reference in New Issue
Block a user