Scripting Custom Steps

Autobahn DX allows custom job steps to be defined that can be included in a Job Definition in the same way as any other step type.

The custom step itself starts with a Windows Script File in the Custom folder of the Autobahn DX installation. This can be the complete script to be executed or the interface to any form of executable file or script.

Some template wsf scripts are included which demonstrates calling a command-line executable from within the script.

Custom Script Example

The ‘Custom Script Step’ if found in the ‘Advanced’ section of the designer.

Custom script files must be placed in “<installation folder>\Autobahn DX\custom folder”. For this example, the custom script file used is called testarguments.wsf. It simply returns the arguments that autobahn sends to the script. This file can be found in the custom folder by default

The result of this custom script is shown in the logging of the running job:

Named arguments

i**n has value C:\Aquaforest\Autobahn DX\samples\pdf

out has value C:\Aquaforest\Autobahn DX\samples\pdf_output

type has value folder

If you require any advice for using a custom script, please contact the support team.

Building a Custom Script

Use case – Script only

The client has a large number of files containing scanned images. A large proportion of these images are either of poor quality (hand-written, badly scanned, or damaged originals) or contain mainly pictorial information with minimum text.

To improve the searchability of the PDFs, XML documents have been prepared (either by hand or by image recognition) to identify the contents.

These files are in pairs, named:

<filename>.pdf

<filename>.xml

For example: File1.pdf and File1.xml

Graphical user interface, text, application Description automatically generated

The requirement is to produce searchable PDF files comprising the original PDF and the XML document of each pair.

The script is going to group each PDF-XML pair in an individual sub folder in the output folder.

The rest of the Autobahn DX job can be accomplished using normal Autobahn steps.

The Script

The following assumes a small amount of knowledge of the Microsoft JScript language (which is a Microsoft version of the JavaScript/ECMAScript language). The Custom Script Example above shows the information provided to the script by Autobahn DX.

WSF wrapper

All WSF scripts require the following wrapper elements.

This example is in Jscript, but other languages are available.

<job>

<script language=“JScript”>

The Jscript code goes here

</script>

</job>

Jscript code

The full script is in the Custom sub folder of the Autobahn DX installation.

The first operation in the script is to obtain the source (In) and target (Out) folders.

var InFolder = “”;

var OutFolder = “”;

if(WScript.Arguments.Named.Exists(“in”)){

InFolder = WScript.Arguments.Named(“in”);

}

if(WScript.Arguments.Named.Exists(“Out”)){

OutFolder = WScript.Arguments.Named(“Out”);

}

If there are values for the InFolder and OutFolder,

if(OutFolder!=”” && InFolder!=””){

then create a File System Object (FSO) and use it to get the InFolder, the files in the InFolder and the OutFolder.

var objFSO=WScript.CreateObject(“Scripting.FileSystemObject”);

var objFolder = objFSO.GetFolder(InFolder);

var colFiles =objFolder.Files;

// Remove any trailing ’\ in supplied Out path

OutFolder = objFSO.GetFolder(OutFolder);

For each file in the InFolder

for(var objEnum = new Enumerator(colFiles);!objEnum.atEnd(); objEnum.moveNext()) {

sFileName = objEnum.item();

sOutName = OutFolder +”\”;

var rootName = objFSO.GetFileName(sFileName);

If the file has a suffix of “pdf”, if there is no sub folder create it, then create the output file name by prefixing the original name with the letter ‘a’.

if(objFSO.GetExtensionName(sFileName) == “pdf”)

{

rootName = rootName.substring(0,rootName.length-4)

sOutName = sOutName + rootName;

if(!objFSO.FolderExists(sOutName)){

objFSO.CreateFolder(sOutName);

}

sOutName = sOutName + “\a” + objFSO.GetFileName(sFileName);

}

If the file has a suffix of “xml”, if there is no sub folder create it, then create the output file name by prefixing the original name with the letter ‘b’

else if(objFSO.GetExtensionName(sFileName) == “xml”)

{

rootName = rootName.substring(0,rootName.length-4)

sOutName = sOutName + rootName;

if(!objFSO.FolderExists(sOutName)){

objFSO.CreateFolder(sOutName);

}

sOutName = sOutName + “\b” + objFSO.GetFileName(sFileName);

}

Any other suffix is an error so quit with an exit code of 2

else

{

WSH.Echo(“Unrecognised file type”);

WSH.Echo(sFileName);

WSH.Quit(2);

}

Record the filename to the log and copy the file out

WSH.Echo(sOutName)

// Copy the file (overwriting any existing file)

objFSO.CopyFile (sFileName,sOutName,true);

}

Record that it has completed and return an exit code of 0.

// Quit with value 0

WSH.Echo(“Done”);

WSH.Quit(0);

}

If there are missing parameters, record an error and return an exit code of 1.

// Else there are one or more missing parameters

//so quit with error

else

{

WSH.Echo(“Missing Named Parameter(s)”);

WSH.Quit(1);

}

The Autobahn DX Job

The Autobahn job comprises three steps:

  • The call to the custom script step

  • Convert any file to searchable PDF

  • Merge PDF

The Merge PDF step merges the contents of each sub folder into an individual PDF.