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

Post Reply
Posts: 20
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() );

Post Reply