Page 1 of 1

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

Posted: Fri Nov 29, 2019 12:06 pm
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() );
}

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

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

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

Posted: Mon Dec 23, 2019 2:09 pm
by gabrielp
Is this a duplicate of viewtopic.php?f=13&t=3484 ?