Sorry guys, I was to tired yesterday when I started playing around to build a flow.
My main goal is to split pdf per page and read data from pdf, eventually output everything to a csv file.
For now this is how it looks:
PDF Splitter -Method Split on page (1 page per output)
Set Job Infos - based on the region where is the only place where I can get data to manipulate
Run Script - purpose: grab the %{blocAdresa} and start playing with regex in order create a csv with lines of data. For nowm my script looks like this:
var fileLocation = get(“workDir”) + “\temp\raport_notificari” + “.csv”
var csvHeader = ‘codClient|denumireClient’;
var curentLoop = Watch.ExpandString(“%i”);
createFile(fileLocation, csvHeader);
var blocAdresa = “”;
var blocAdresa = get(“blocAdresa”);
//yes it’s a match
var codClient = blocAdresa.match(/Catre:\s+([\w]+)\s±/i)[1];
var denumireClient = blocAdresa.match(/-\s+(.+)\s+ Adresa/i)[1];
//View in Debug Mode
Watch.Log(blocAdresa, 3)
Watch.Log(codClient,2);
Watch.Log(denumireClient,2);
var lineOfText = [codClient, denumireClient].join(‘|’);
// write the line of text to the fileOut
appendFile(fileLocation, lineOfText);
//go to newline for new text
var outputFile = set(“fileName”, fileLocation);
/* Helpers */
function appendFile(path, content) {
var fs = new ActiveXObject(‘Scripting.FileSystemObject’)
var file = fs.OpenTextFile(path, 8, true)
file.WriteLine(content)
file.Close()
}
function get(name) { return typeof name === ‘number’ ? Watch.getJobInfo(name) : Watch.getVariable(name) }
function set(name, value) { typeof name === ‘number’ ? Watch.setJobInfo(name, value) : Watch.setVariable(name, value) }
function log(msg) { try { Watch.log(toString(msg), 2) } catch(e) { WScript.stdout.WriteLine(toString(msg)) } }
function err(msg) { try { Watch.log(toString(msg), 1) } catch(e) { WScript.stdout.WriteLine(toString(msg)) } }
function exp(string) { return Watch.expandString(string); }
function xml(string) { return Watch.expandString(“xmlget('/request[1]/values[1]/” + string + “[1]',Value,KeepCase,No Trim)”); }
function toString(value) { try { return JSON.stringify(value) } catch(e) { return ‘’+value } }
function format() {
var as = arguments
return as[0].replace(/{ *(\w+) *}/g,
function(m, i) { return as[i] })
}
function sanitizeFilename(filename) {
return filename.replace(//|\|:|?|*|"|||<|>/g, ‘-’)
}
function writeFile(path, content){
var fs = new ActiveXObject(‘Scripting.FileSystemObject’)
var file = fs.OpenTextFile(path, 8, true)
file.Write(content)
file.Close()
}
function createFile(path, content){
var fs = new ActiveXObject(“Scripting.FileSystemObject”)
var file = fs.CreateTextFile(path)
file.WriteLine(content)
file.Close()
}
/**
- helper function to wrap text in quotes for escaping
- @param {string} text
*/
function wrappInQuotes(text) {
return ‘"’ + text + ‘"’
};
Everything works expected, except every time there is a next iteration in pdf splitter my line of text is not appended, it’s overwritten…