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 {
|
||||
static createAnnotations(document) {
|
||||
static async createAnnotations(document) {
|
||||
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(formField)
|
||||
})
|
||||
|
||||
return {
|
||||
signatures: signatures
|
||||
signatures.push(annotation2)
|
||||
signatures.push(formFieldDate)
|
||||
}
|
||||
|
||||
return [...signatures ]
|
||||
}
|
||||
|
||||
static createSignature(element) {
|
||||
static async createSignature(element) {
|
||||
const id = PSPDFKit.generateInstantId()
|
||||
const width = Annotation.inchToPoint(element.width)
|
||||
const height = Annotation.inchToPoint(element.height)
|
||||
const top = Annotation.inchToPoint(element.top) - height / 2
|
||||
const left = Annotation.inchToPoint(element.left) - width / 2
|
||||
const page = element.page - 1
|
||||
console.log(id)
|
||||
|
||||
//signatures
|
||||
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id,
|
||||
pageIndex: page,
|
||||
@ -39,7 +41,31 @@
|
||||
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) {
|
||||
|
||||
@ -70,8 +70,8 @@ class App {
|
||||
// Load annotations into PSPDFKit
|
||||
try {
|
||||
this.signatureCount = this.currentDocument.elements.length
|
||||
const annotations = Annotation.createAnnotations(this.currentDocument)
|
||||
await this.Instance.create(annotations.signatures)
|
||||
const annotations = await Annotation.createAnnotations(this.currentDocument)
|
||||
await this.Instance.create(annotations)
|
||||
|
||||
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