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

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

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

Post by automation » Fri Nov 29, 2019 12:06 pm

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: 74
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 » Mon Dec 23, 2019 10:27 am

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 » Mon Dec 23, 2019 2:09 pm

Is this a duplicate of viewtopic.php?f=13&t=3484 ?
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