Copy link to clipboard
Copied
Hi,
I am checking indesign document size through the script comparing it to order specs, and it works great with standard numbers (if I can call them that way), like 3.5x2, 4x6, 2.125x2.125, etc.
But when I get strange numbers, like 1.8x4.1, it tells me that size is wrong when size is correct. Why would it matter what kind of number it is and how I can make it work?
Here is my script (I check both orientations):
if((myXmlWidth == myPageWidth && myXmlHeight == myPageHeight) || (myXmlWidth == myPageHeight && myXmlHeight == myPageWidth)){
}else{
alert("Incorrect document size.");
exit();
}
Thank you
Yulia
Copy link to clipboard
Copied
Weird indeed. Might this be a rounding issue ?
InDesign may display a rounded value while the geometric bounds may return non rounded values.
Eventually 1.99999 isn't 2
FWIW
Copy link to clipboard
Copied
Here's a function which I use to deal with the rounding error:
function RoundWithDecimal(number, decimals) {
var multiplier = Math.pow(10, decimals);
return Math.round(number * multiplier) / multiplier;
}
gb = frame.geometricBounds;
left = RoundWithDecimal(gb[1], 3);
right = RoundWithDecimal(gb[3], 3);
top = RoundWithDecimal(gb[0], 3);
bottom = RoundWithDecimal(gb[2], 3);
width = right - left;
height = bottom - top;
Copy link to clipboard
Copied
Thank you, Kasyan,
Your approach gave different idea that worked for me too. I am comparing them like strings instead of numbers now:
if((docNameSize == myPageWidth+"x"+myPageHeight) || (docNameSize == myPageHeight+"x"+myPageWidth)){
}else{
alert("Incorrect document size. \nReload xml and InDesign file and re-apply template script.");
exit();
}
Thank you
Yulia