2 Replies Latest reply on Feb 4, 2013 12:50 AM by MrTIFF

    Size of placed PDF Page

    pkrk Level 1

      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.

        • 1. Re: Size of placed PDF Page
          Vamitul Level 4

          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);
              }

          • 2. Re: Size of placed PDF Page
            MrTIFF Level 3

            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"