Skip to main content
Inspiring
February 1, 2013
Question

Size of placed PDF Page

  • February 1, 2013
  • 1 reply
  • 779 views

After placing a page from a PDF, I want to display the size of the page in a text frame.

The closest to the size of the PDF page that I get is when using

app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;

Sometimes I get and expected size like 8.5 by 11 but some PDFs give me a size of 8.4###### x 10.9######.

If I open up the PDF in acrobat that in indesign showed 8.4###### x 10.9######, it shows 8.5 x 11.

Is my only way around this is to set up some rounding/precision routine?

Thank you in advance!

** I calculate the size but it starts with geomtric bounds having a lot more decimal places than expected.

This topic has been closed for replies.

1 reply

Vamitul
Legend
February 4, 2013

use javascript's math rounding methods (floor, ceil, round). i don't know if ExtendeScript supports the .toFixed method, but that would be great.

if not, here is a prototype for it (don't know where i got it, it's in my library for some time now, and i don't think i ever used it):

    Number.prototype.toFixed = function(precision) {
        var power = Math.pow(10, precision || 0);
        return String(Math.round(this * power)/power);
    }

MrTIFF
Participating Frequently
February 4, 2013

Yes, ExtendScript does support toFixed(), but you need a toFixed() that also trims any trailing zeros:

/**
* same as toFixed(), but trims off those annoying trailing zeros
*
* @param decimalPlaces maximum number of digits to the right of the decimal point
* @returns the same string as toFixed(), except that any trailing zeros are removed
*/
Number.prototype.toFixedNice = function(/**Number*/decimalPlaces) /**String*/
{
     return Number(this.toFixed(decimalPlaces)).toString();
};

So if you include the above in your extendscript, you can do this:

var x = .999999999999;
alert(x.toFixedNice(5)); // gives "1", instead of "1.00000"