Smartstream Question

Post Reply
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Smartstream Question

Post by gabrielp » Thu Feb 25, 2016 6:53 pm

Does anyone know if the smartsrteam design can be used to output different files? We have a client that wants a separate PDF for each record. My first thought is, just split it within Switch. But they want the files named according to a variable in the database, so I'm not sure how to make that happen.

Any ideas?
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

If I've helped you and you'd like to say thanks, consider adding me on LinkedIn and leaving me an endorsement or recommendation. It helps a lot!

User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Smartstream Question

Post by gabrielp » Thu Feb 25, 2016 7:53 pm

And to simplify this question: can you pull text out of a PDF via Switch or Pitstop? If so, we could tie the variable to a hidden field in the PDF.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

If I've helped you and you'd like to say thanks, consider adding me on LinkedIn and leaving me an endorsement or recommendation. It helps a lot!

lombert
Member
Posts: 167
Joined: Fri Feb 04, 2011 2:31 pm
Location: Sweden

Re: Smartstream Question

Post by lombert » Fri Feb 26, 2016 8:18 am

gabrielp wrote:And to simplify this question: can you pull text out of a PDF via Switch or Pitstop? If so, we could tie the variable to a hidden field in the PDF.
Answer to this, you can use PdfSpy from Apago. It has an function that reads text and make it metadata.. Have used it with some jobs.
Between jobs!

lombert
Member
Posts: 167
Joined: Fri Feb 04, 2011 2:31 pm
Location: Sweden

Re: Smartstream Question

Post by lombert » Fri Feb 26, 2016 8:31 am

I got this from Dwight at Apago..

Code: Select all

// PDFspy text search
// (c) 2012-2014 by Apago, Inc.
// All rights reserved
//
// Created by Dwight Kelly <dkelly@apago.com>
// Date: 2012/01/20
// Modified: 2014/11/31

// Switch logging & output levels
const cLogAssert = -2;
const cLogDebug = -1;
const cLogInfo = 1;
const cLogWarning = 2;
const cLogError = 3;
const cLogProgress = 5;

const cSendSuccess = 1;
const cSendWarning = 2;
const cSendError = 3;
	
function isolate( job : Job, str : String, matchPos : Integer ) : String
{
	// trim left side
	if (matchPos > 1)
		str = str.substring(matchPos);

	var ltPos = matchPos;
	if (str.charAt(ltPos) == ' ')  // watch out for leading spaces
		ltPos++;

	var parts = str.split(" ");
	if (parts.length > 1)
		return parts[1];
	return "";
}

function jobArrived( s : Switch, job : Job )
{
    if (job.isFolder()) {
        job.fail( "This configurator cannot handle job folders" );
        return;
    }

	if (!job.isType("pdf")) {
		job.fail("This configurator only supports PDF");
		return;
	}
	
	var appPath;
	if (s.isMac())
		appPath = "/Applications/pdfspy/pdfspy";
	else
		appPath = "c:/Program Files (x86)/Apago/PDFSpy/pdfspy";
	
	var String args = new Array();
	var argc = 0;
	args[argc++] = appPath;
	args[argc++] = "-text";
	var String outFile = job.createPathWithExtension("txt", false); // output file
	args[argc++] = "-o";
	args[argc++] = outFile;
	args[argc++] = job.getPath();  // input file
	var exitStatus = Process.execute(args);
	if (exitStatus != 0) {
		// failure
		job.log(cLogError, "Could not extract text from PDF");
		job.sendToData( cSendError, job.getPath() );
		return;
	}
	if (!File.exists(outFile)) {
		// failure
		job.log(cLogError, "Could not open text file " + outFile);
		job.sendToData( cSendError, job.getPath() );
		return false;
	}

	var textFile = new File( outFile, "UTF-8" );
	textFile.open(File.ReadOnly);
	var theMarker = s.getPropertyValue("marker");
	var theSearchType = s.getPropertyEditor("marker");
	var theRegEx = (theSearchType == "Single-line text") ? theMarker : new RegExp(theMarker);
	var cnt = 0, matchPos;
	do {
		var line = textFile.readLine();
		if (cnt++ == 0 && line.charCodeAt(0) == 0x0c) {
			// blank page
			textFile.close();
			var jobid = job.getNameProper().split("_");
			job.setPrivateData("ExtractedName", jobid[0]);
			//job.log(cLogInfo, "Blank page '" + jobid[0] + "'");
			job.sendToData( cSendSuccess, job.getPath() );
			return;
		}
		matchPos = line.search(theRegEx);
		if (matchPos >= 0) {
			line = isolate(job, line, matchPos);
			if (line.length > 0) {
				textFile.close();
				job.setPrivateData("ExtractedName", line);
				job.log(cLogInfo, "Extracted name = '" + line + "'");
				job.sendToData( cSendSuccess, job.getPath() );
				return;
			}
		}
	} while (!textFile.eof);
	
	// failure
	textFile.close();
	job.log(cLogError, "Could not find the marker text");
	job.sendToData( cSendError, job.getPath() );
}
Image

Image
Between jobs!

User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Smartstream Question

Post by gabrielp » Fri Feb 26, 2016 7:54 pm

Thanks man. I'll look into PDFSpy.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

If I've helped you and you'd like to say thanks, consider adding me on LinkedIn and leaving me an endorsement or recommendation. It helps a lot!

lombert
Member
Posts: 167
Joined: Fri Feb 04, 2011 2:31 pm
Location: Sweden

Re: Smartstream Question

Post by lombert » Mon Feb 29, 2016 9:59 am

No problem, glad if it helped!

And as an example you use the "Marker" text as trigger. It looks for that text and to the next "space" I think it was..
Between jobs!

User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Smartstream Question

Post by gabrielp » Tue Mar 01, 2016 12:03 am

Got it working today with some help from Dwight. Thanks Lombert. PDFSpy is super useful. 8-)
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

If I've helped you and you'd like to say thanks, consider adding me on LinkedIn and leaving me an endorsement or recommendation. It helps a lot!

Post Reply