IDT: Gelangensbestätigung

by Alexey Demin

HTML

<p>Select text file with PDFBox output: <input type="file" id="PDFBox-output" name="PDFBox-output" /><p/>
<p><button id="parseIt" name="parseIt" disabled="disabled">Parse it!</button></p>
<p>PDFBox output:<br/>
    <textarea id="raw" name="raw"></textarea></p>
<p>Parsed:<br/>
    <textarea id="res" name="res"></textarea></p>

CSS

* { font-family: Arial "Helvetica", sans-serif; }
textarea {
    width: 100%;
    height: 200px;
    font-family: monospace;
}

JavaScript

(function ($) {
    
    var opt = {
        "splitWith" : "\n",
        "joinWith" : " ",
        "useTrim" : true,
        "profiles" : {
            "ups" : {
                // Check function, which called for every line.
                // Returns 'true' for success and 'false' for fail.
                "checkAttempt" : 20,
                "check" : function (line){
                    return String(line).indexOf('UPS Kundennummer') == -1 ? false : true;
                },
                "regex" : {
                    "lineBegin" : "((?:1Z[A0-9]{16})|(?:H[0-9]{10}))(.+?)([0-9]{2}[.][0-9]{2}[.][0-9]{4})",
                    "matrixRegex" : "((?:1Z[A0-9]{16})|(?:H[0-9]{10}))(.+?)([0-9]{2}[.][0-9]{2}[.][0-9]{4})",
                    "matrix" : [
                        {"name" : "Kontrollnummer"},
                        {"name" : "Referenznummer",
                            "postProcess" : function(text){
                                text = text.split("IDT").join("").trim();
                                var len = parseInt(text.length, 10);
                                if(len % 6 != 0 || len == 0){
                                    return false;
                                }
                                if(len == 6 || len == 7){
                                    return text;
                                }
                                for(var i = 0, res = []; i < len / 6; i++){
                                    res.push(text.substring(i*6, (i*6)+6));
                                }
                                return res.join(" ");
                            }
                        },
                        {"name" : "Manifestdatum"}
                    ]
                }
            },
            "gls" : {
                "checkAttempt" : 20,
                "check" : function (line){
                    return String(line).indexOf('GLS Track ID') == -1 ? false : true;
                },
                "regex" : {
  ...