PageWidth how to assign a value to a variable?

menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

PageWidth how to assign a value to a variable?

How to use PageWidth variable in JavaScript?
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

PageWidth how to assign a value to a variable?

Post by freddyp »

var pageWidth = job.getVariableAsNumber("[Stats.PageWidth]");
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

Really worked, thank you very much.
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

var re =job.getPath();

re=re.mid(0,re.findRev("/")) + "/"+job.getName();

var curFileStats = new FileStatistics(re);

currentbook = curFileStats.getNumber("PageWidth");



why can't work?
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PageWidth how to assign a value to a variable?

Post by dkelly »

Is your job a file or folder?
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

dkelly wrote: Is your job a file or folder?


my job is a file.
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

how to use function FileStatistics?
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PageWidth how to assign a value to a variable?

Post by dkelly »

If your job is a single file use:



var curFileStats = new FileStatistics(job.getPath());

currentbook = curFileStats.getNumber("PageWidth");
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

dkelly wrote: If your job is a single file use:



var curFileStats = new FileStatistics(job.getPath());

currentbook = curFileStats.getNumber("PageWidth");


I tried, but without success.

Can you give me an example of flow?







test.sflow
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PageWidth how to assign a value to a variable?

Post by dkelly »

Your script doesn't follow the example I gave. You are not using the FileStatistics variable curFileStats to retrieve the PageHeight.
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

dkelly wrote: Your script doesn't follow the example I gave. You are not using the FileStatistics variable curFileStats to retrieve the PageHeight.






return value:undefined
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

dkelly wrote: Your script doesn't follow the example I gave. You are not using the FileStatistics variable curFileStats to retrieve the PageHeight.






return value:undefined



Does anyone know what is the reason?
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

PageWidth how to assign a value to a variable?

Post by freddyp »

The return value of a script expression is the "last" variable on a line of its own.



var result = "1";

result;



If the script expression is more than just one or two lines I recommend to structure it as follows: create a function that returns a value and call that function on the last line of your script expression. You do not have to do it like this, but it is generically applicable.



function someFunction(par1, par2)

{

var returnValue;

//perform stuff that gives returnValue the correct value



return returnValue;

}



someFunction("first parameter",second_parameter);



Freddy
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

PageWidth how to assign a value to a variable?

Post by menglv »

freddyp wrote: Freddy


Theresult of this variable is not important, the key is currentbook which returned the result is undefined. I want this currentbook value equals pdf's PageHeight.
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

PageWidth how to assign a value to a variable?

Post by freddyp »

Then just write



currentbook;



as the last line of your script expression. I thought that was clear from the explanation.



Freddy
Post Reply