file is not a valid pdf file

Post Reply
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

file is not a valid pdf file

Post by LasseThid »

I'm working on a flow for automation of our business card production.
After the files are dropped in a hot folder I use this script to determine which template to use for the imposition.

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	var width = job.getVariableAsNumber("[Stats.TrimboxWidth]"); 
	var height = job.getVariableAsNumber("[Stats.TrimboxHeight]");   
	var inputJob = job.getPath();
	var theFileName = job.getNameProper()
	templateWidth = Math.floor((width/72)*25.4+0.5);
	templateHeight = Math.floor((height/72)*25.4+0.5);			
	templateName = templateWidth+'x'+templateHeight;
	job.setPrivateData( "template", templateName );
	job.sendToSingle( inputJob, theFileName );
}
The file is then sent to the HP SmartStream Designer Imposition, but at this stage I get an error saying that the file is not a valid pdf file.

If I make a duplicate of the flow and send the pdf directly to the SmartStream designer I don't get this error, so I'm guessing the problem has to be related to something with my script.

Any suggestions?
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
bens
Advanced member
Posts: 253
Joined: Thu Mar 03, 2011 10:13 am

Re: file is not a valid pdf file

Post by bens »

Code: Select all

var theFileName = job.getNameProper()
//...
job.sendToSingle( inputJob, theFileName );
The function getNameProper() returns the filename without extension (and without unique ID). So, if your incoming file is "file.pdf", then theFileName will be "file".
The second parameter in job.sendToSingle() is a new name for the job. So in essence, the combination of these two lines will strip the extension from the file. In other words: "file.pdf" will be renamed to "file". Apparently HP SmartStream looks at the extension to determine whether a file is a PDF, and rejects files without extension.

You could solve this by explicitly adding the extension back, but there's a better way: the second parameter in sendToSingle() is optional. If you don't add it, the name of the incoming file will be used. This also means that the variable theFileName becomes superfluous, so you can remove it:

Code: Select all

function jobArrived( s : Switch, job : Job )
{
   var width = job.getVariableAsNumber("[Stats.TrimboxWidth]"); 
   var height = job.getVariableAsNumber("[Stats.TrimboxHeight]");   
   var inputJob = job.getPath();
   templateWidth = Math.floor((width/72)*25.4+0.5);
   templateHeight = Math.floor((height/72)*25.4+0.5);         
   templateName = templateWidth+'x'+templateHeight;
   job.setPrivateData( "template", templateName );
   job.sendToSingle( inputJob );
}
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: file is not a valid pdf file

Post by LasseThid »

Thanks for the explanation and the modified code.

I was a bit lazy, so I copy/pasted it into my script and it works perfectly. 8-)
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
Post Reply