Aufrufbeispiel des DocCreator mit JavaScript

Sebastian Bartsch Aktualisiert von Sebastian Bartsch

Ein Anwendungsfall ist den DocCreator direkt aus einem JobRouter Prozess per JavaScript aufzurufen und die erstellte Datei als Download anzubieten ohne das die entsprechende Webseite neugeladen werden muss. Nachfolgender JavaScript Code soll dies veranschaulichen.

const data = {
disableJobRouterIntegration: true,
templateName: "vorlage.docx",
documentFileName: "Ausgabedateiname",
documentAuthor: "DocuScan DocCreator",
mergeFieldMappings: [
{fieldName: "absender_name", fieldValue: $JRUSER.lastName+', '+ $JRUSER.preName},
{fieldName: "absender_tel", fieldValue: "XX"},
{fieldName: "barcode", fieldValue: "DocCreator4711", fieldType: "Barcode",
fieldOptions : {
$type: "DataMatrix",
moduleSize: 1,
dpi: 96,
compactionMode: "Text",
size: "Matrix22x22"}
},
{fieldName: "absender_unterschrift", fieldValue: "steve.png", fieldType: "Image"},
]
}

fetch('https://WEBSERVER/doccreator/api/v1/creator/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept' : '*/*',
'X-Api-Key' : 'xxxyyyzzz12345'
},
body: JSON.stringify(data),
})
.then(handleErrors)
.then(response => response.blob())
.then(blob => {
console.log("ok.")

const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = data.documentFileName + ".docx";
document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
a.click();
a.remove(); //afterwards we remove the element again
})
.catch((error) =>{
console.error('Unable to create a document:', error);
});

Wie waren wir?

Barcodes mit dem DocCreator einbetten

Support