Using an external JSON jobticket file
This example shows how processing information can be taken from a jobticket file, which has been saved next to the currently processed PDF. The jobticket file uses JSON and does in this example only have one key value pair.
The download contains a Profile with a Process Plan, a sample PDF and a JSON jobticket.
The first step in the Process Plan is a Variable that that tries to read the jobticket and stores one of the values in it into the variable "text". It does the same for the text size which is different for regular content and for an error message that is saved into "text" instead if reading the jobticket fails. This variable is made available via app.vars to the next step which takes it and prints its contents onto the PDF page.
This is the variable from the first step.
debug = true;
function buildSidecarFileName( extension )
{
var path = app.doc.path.split(app.env.pathDelimiter);
if (debug) console.log( "buildSidecarFileName 1 Path: " + path);
var name = path[path.length-1].split(".");
if (debug) console.log( "buildSidecarFileName 2 Name: " + name);
name.pop();
if (debug) console.log( "buildSidecarFileName 3 Name: " + name);
name.push(extension);
if (debug) console.log( "buildSidecarFileName 4 Name: " + name);
path.pop();
if (debug) console.log( "buildSidecarFileName 5 Path: " + path);
path.push(name.join("."));
if (debug) console.log( "buildSidecarFileName 6 Path: " + path);
path = path.join(app.env.pathDelimiter)
if (debug) console.log( "buildSidecarFileName 7 Path: " + path);
return new File(path);
}
try
{
app.vars.sidecar = JSON.parse( buildSidecarFileName("json").read());
if (debug) console.log( "main 1 The jobticket file: " + JSON.stringify(app.vars.sidecar));
app.vars.text = app.vars.sidecar.msg;
app.vars.fontsize = 25;
app.vars.ok = true;
}
catch( x )
{
app.vars.text = "ERROR: Could not read message from sidecar file: " + x;
app.vars.fontsize = 20;
app.vars.ok = false;
}
app.vars.ok;
The first call sets the debug variable to true. This allows for reading the current state of processing in the Console window of the JavaScript editor (if "Show evaluation results" is on). This is the output for "testimonial Mercedes.PDF".
buildSidecarFileName 1 Path: ,Users,d.seggern,Doku,Reading a jobticket from a sidecar file (JSON),testimonial Mercedes.pdf
buildSidecarFileName 2 Name: testimonial Mercedes,pdf
buildSidecarFileName 3 Name: testimonial Mercedes
buildSidecarFileName 4 Name: testimonial Mercedes,json
buildSidecarFileName 5 Path: ,Users,d.seggern,Doku,Reading a jobticket from a sidecar file (JSON),
buildSidecarFileName 6 Path: ,Users,d.seggern,Doku,Reading a jobticket from a sidecar file (JSON),testimonial Mercedes.json
buildSidecarFileName 7 Path: /Users/d.seggern/Doku/Reading a jobticket from a sidecar file (JSON)/testimonial Mercedes.json
main 1 The jobticket file: {“msg”:”This string came from a sidecar file!”}
The Console output shows how the path for the jobticket file is built from the path of the PDF file, in the lines starting with "buildSidecarFileName" and the contents of the jobticket file, which is rather short in this example.