Switchscripter can't combine value from pdf and xml in one variable

Post Reply
automation
Member
Posts: 40
Joined: Tue Jan 15, 2019 10:19 pm

Switchscripter can't combine value from pdf and xml in one variable

Post by automation »

I have a script in Switchscripter with incoming one pdf and one XML.
If the job is XML I get the value from the XML (works inside the function)
if the job is a PDF I get the size of the PDF (works inside the function)

But when I "convert mm to pt" I get two values in trimBoxWidht and trimBoxHeight sense both the pdf and xml pass this.

I also get double X and Y.

How do I get one calculated X and Y with the combination of the info from the PDF and the XML.

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	var PrintWidthCover = 0;
	var PrintHeightCover  = 0;
	var pdfWidth  = 0;
	var pdfHeight  = 0;	
	
	if(job.isType("xml")) {
		//Get Widht and Height from the XML
		var theXML = new Document(job.getPath());
		
		PrintWidthCover = theXML.evalToString("//PrintWidthCover");
		PrintHeightCover = theXML.evalToString("//PrintHeightCover");
	}
	
	if(job.isType("pdf")) {		
		//Get size of the pdf
		pdfWidth = job.getVariableAsNumber("[Stats.PageWidth]");
		pdfHeight = job.getVariableAsNumber("[Stats.PageHeight]");
	}

	//convert mm to pt
	var trimBoxWidht = PrintWidthCover * 2.83464567;
	var trimBoxHeight = PrintHeightCover * 2.83464567;


	//calculate starting point
	startX = (pdfWidth - trimBoxWidht)/2;
	startY = (pdfHeight - trimBoxHeight)/2;

	s.log(2, "-- pdfWidth: " + pdfWidth);
	s.log(2, "-- trimBoxWidht: " + trimBoxWidht);
	
	s.log(2, "---Start X: " + startX);
	s.log(2, "----Start Y: " + startY);	
	
	job.sendToNull( job.getPath() );
}
r.zegwaard
Member
Posts: 93
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

Re: Switchscripter can't combine value from pdf and xml in one variable

Post by r.zegwaard »

Your script will run on arrival of a pdf OR xml
So when the pdf arrives, your script doesn't have the values of the xml and vice versa.

So you could adjust the flow and script to attach the xml as metadata to the pdf and after that run the script.
In that case the script can retrieve the xml-values from the xml-dataset.
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Switchscripter can't combine value from pdf and xml in one variable

Post by gabrielp »

Is this a duplicate of viewtopic.php?f=13&t=3484 ?
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Post Reply