9 Replies Latest reply on Mar 20, 2012 2:28 PM by bobhopfner

    Scaling document truncates bottom-most page object

    bobhopfner Level 1

      Obviously, this is undesireable, but I am unsure what my script or InDesign is doing to cause this to happen. The output gets cropped off right to the last object on the page.

       

      The purpose of this script is to grab a document and scale everything on the page by a factor of (X) and then reduce the page dimensions by the same amount. Final output is a pdf.

       

      I am getting the scaling factor externally. I thought perhaps the bleed dimensions were causing some error as the page scaled. I tried to specify bleeds in the PDF export but that didn't seem to work although I may have set them wrong. I am not sure my whole approach is the best either at this point. I will clarify any points as best I am able. This script is running on InDesign Server CS5 and not just on the desktop.

       

      Thanks for your help.

       

      Bob Hopfner

       

      My script is this:

       

      var myDocument = app.documents.item(0);

      var myPages = myDocument.pages;

      var myRectangle = myDocument.pages.item(0).pageItems;

       

      var userData = app.scriptArgs.getValue("UserData");

      var ssize = parseFloat(userData);

       

      //Scale a page around its center point.

      var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:ssize, verticalScaleFactor:ssize});

       

      myTransform(myPages.item(0), myRectangle, myScaleMatrix);

       

      myPDFExport ();

       

      function myTransform(myPage, myRectangle, myScaleMatrix)

      {

          var everything = myRectangle.everyItem();

          everything.transform(CoordinateSpaces.PASTEBOARD_COORDINATES,AnchorPoint.CENTER_ANCHOR,my ScaleMatrix);

         

          myPage.transform(CoordinateSpaces.PASTEBOARD_COORDINATES,AnchorPoint.CENTER_ANCHOR,myScal eMatrix);

      }

       

      function myPDFExport()

      {

              //Basic PDF output options.

              pageRange = PageRange.allPages;

      acrobatCompatibility = AcrobatCompatibility.acrobat8;

      exportGuidesAndGrids = false;

              exportLayers = false;

      exportNonPrintingObjects = false;

              exportReaderSpreads = false;

      generateThumbnails = false;

             

              try

              {

      ignoreSpreadOverrides = false;

              }

              catch(e) {}

             

              includeBookmarks = false;

              includeHyperlinks = false;

      includeICCProfiles = true;

      includeSlugWithPDF = false;

              includeStructure = false;

      interactiveElementsOption = InteractiveElementsOptions.doNotInclude;

             

              //Setting subsetFontsBelow to zero disallows font subsetting;

              //set subsetFontsBelow to some other value to use font subsetting.

              subsetFontsBelow = 0;

       

              //Bitmap compression/sampling/quality options.

      colorBitmapCompression = BitmapCompression.none;

      //colorBitmapQuality = CompressionQuality.eightBit;

      colorBitmapSampling = Sampling.none;

       

      //thresholdToCompressColor is not needed in this example.

      //colorBitmapSamplingDPI is not needed when colorBitmapSampling

              //is set to none.

      grayscaleBitmapCompression = BitmapCompression.none;

      //grayscaleBitmapQuality = CompressionQuality.eightBit;

      grayscaleBitmapSampling = Sampling.none;

      //thresholdToCompressGray is not needed in this example.

      //grayscaleBitmapSamplingDPI is not needed when grayscaleBitmapSampling

              //is set to none.

      monochromeBitmapCompression = BitmapCompression.none;

      monochromeBitmapSampling = Sampling.none;

       

      //thresholdToCompressMonochrome is not needed in this example.

              //monochromeBitmapSamplingDPI is not needed when

      //monochromeBitmapSampling is set to none.

              //

              //Other compression options.

              compressionType = PDFCompressionType.compressNone;

      compressTextAndLineArt = true;

              cropImagesToFrames = true;

              optimizePDF = true;

             

              //Printers marks and prepress options.

              //Get the bleed amounts from the document's bleed.

      //~ bleedBottom = myDocument.documentPreferences.documentBleedBottomOffset;

      //~         bleedTop = myDocument.documentPreferences.documentBleedTopOffset;

      //~ bleedInside = myDocument.documentPreferences.documentBleedInsideOrLeftOffset;

      //~ bleedOutside = myDocument.documentPreferences.documentBleedOutsideOrRightOffset;

      //~         //If any bleed area is greater than zero, then export the bleed marks.

      //~ if(bleedBottom == 0 && bleedTop == 0 && bleedInside == 0 && bleedOutside == 0)

      //~         {

      //~ bleedMarks = true;

      //~         }

      //~         else

      //~        {

      //~ bleedMarks = false;

      //~        }

      //~        colorBars = false;

       

              colorTileSize = 128;

              grayTileSize = 128;

              cropMarks = false;

              omitBitmaps = false;

              omitEPS = false;

              omitPDF = false;

      pageInformationMarks = false;

              pdfColorSpace = PDFColorSpace.unchangedColorSpace;

              //Default mark type.

              pdfMarkType = 1147563124;

              printerMarkWeight = PDFMarkWeight.p125pt;

              registrationMarks = false;

       

              try

              {

      simulateOverprint = false;

              }

              catch(e) {}

             

              useDocumentBleedWithPDF = false;

             

              viewPDF = false;

       

          //Now export the document.

          var thisDocument = app.documents.item(app.documents.length-1);

          var fullname = app.scriptArgs.getValue("OutputFileName");

          var idx = fullname.indexOf("_");

          var shortname = fullname.substring(0, idx);

      thisDocument.exportFile(ExportFormat.pdfType, app.scriptArgs.getValue("OutputFolder") + shortname + ".pdf");

      }

        • 1. Re: Scaling document truncates bottom-most page object
          John Hawkinson Level 5

          Try reducing this to the simplest possible script/case where this happens.

          • 2. Re: Scaling document truncates bottom-most page object
            bobhopfner Level 1

            I think this is the simplest version of the script, minus all the pdf export settings - althought I thought maybe they would be important. As far as when this happens it is all the time. I haven't run it against a lot of files but it seems to me there is something more wrong with the script than the file. To illustrate, consider a 5"x5" document with a 4"x3" text box. The script creates a pdf scaled to the desired percentage but for some reason crops the bottom of the document off - but the document is acutually the correct size. It adds the extra space at the top from what I can see.

             

            thanks,

            Bob

             

            var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:ssize, verticalScaleFactor:ssize});

            function myTransform(myPage, myRectangle, myScaleMatrix)

            {

                 var everything = myRectangle.everyItem();

                 everything.transform(CoordinateSpaces.PASTEBOARD_COORDINATES,AnchorPo int.CENTER_ANCHOR,myScaleMatrix);

                     myPage.transform(CoordinateSpaces.PASTEBOARD_COORDINATES,AnchorPoint. CENTER_ANCHOR,myScaleMatrix);

            }

             

            //Now export the document.

                 var thisDocument = app.documents.item(app.documents.length-1);

                 var fullname = app.scriptArgs.getValue("OutputFileName");

                 var idx = fullname.indexOf("_");

            var shortname = fullname.substring(0, idx);

            thisDocument.exportFile(ExportFormat.pdfType, app.scriptArgs.getValue("OutputFolder") + shortname + ".pdf");

            • 3. Re: Scaling document truncates bottom-most page object
              Marc Autret Level 4

              Hi Bob,

               

              First of all, make sure that app.transformPreferences.whenScaling is set to WhenScalingOptions.APPLY_TO_CONTENT, otherwise page scaling will not actually change the dimensions of the page. When app.transformPreferences.whenScaling is set to WhenScalingOptions.ADJUST_SCALING_PERCENTAGE, any scaling applied to a page only transforms the view in the app interface, but the exported page has its original size preserved. Note that in both cases, transforming a page has no visible effect on the underlying page items, but this makes a crucial difference in the exported document as the PDF is based on the actual size of the page(s).

               

              Now, the problem in your myTransform function is that the transformation origin is not the same in everything.transform(...) and myPage.transform(...). When an object is scaled, the origin of the transformation matters in that it determines how that object will move. So, when you need to scale two objects while preserving their relative location, you have to use the same origin. Note that the origin of a transformation is never saved in a TransformationMatrix, so you need to explicitly provide the transformation origin each time you apply a matrix.

               

              In the transform method, the origin is the second argument. There are many way to specify that location—the Adobe documentation is pretty unclear about this. What you need to know is that AnchorPoint.CENTER_ANCHOR in everything.transform(…) and in myPage.transform(…) does not refer to the same location (unless by chance the center point of the everything object be the center point of the page).

               

              So I suggest you use the center point of the page for both transformations, as in the following code:

               

               

              function myTransform(myPage, myRectangle, myScaleMatrix)
              {
                  var everything = myRectangle.everyItem(),
                      origin = myPage.resolve(AnchorPoint.CENTER_ANCHOR,CoordinateSpaces.PASTEBOARD_COORDINATES)[0];
              
                  everything.transform(
                      CoordinateSpaces.PASTEBOARD_COORDINATES,
                      origin, // absolute coord. in the pasteboard space
                      myScaleMatrix);
              
                  myPage.transform(
                      CoordinateSpaces.PASTEBOARD_COORDINATES,
                      origin, // absolute coord. in the pasteboard space
                      myScaleMatrix);
              }
              

               

              Hope that helps.

               

              @+

              Marc

              1 person found this helpful
              • 4. Re: Scaling document truncates bottom-most page object
                bobhopfner Level 1

                So, it turns out that it wasn't the script causing the problem but a text box that extended beyond the document AND a missing font on the server that was causing the text box to fill up to the edge of the page.

                 

                BUT, the info above is great and we're using that code including app.transformPreferences.whenScaling = WhenScalingOptions.APPLY_TO_CONTENT,

                 

                Now though we seem to have another issue as all of the elements are not maintaining their position after the scaling occures. We have some text highlighted by a yellow box behind the copy, but as we scale the text box the hightlight objects also scale but are subltely repositioned and not aligned with the original text. If I scale the document below 50%, in some instances the box shrinks yet the copy within doesn't shrink enough which causes the text to reflow (very undesirable for the client).

                 

                I am going to try to group these elements to see if that will help maintain their relationship to each other.

                 

                Am I looking at some sort of itterative process next that runs through each object on the page and scales/repositions each object individually or is there something else I can try?

                 

                Also, is there anything that prevents a document from being scaled up? It hits the "object extends beyond the pasteboard" error. Anyone know someway around that?

                 

                Thanks very much for your help,

                 

                Bob

                • 5. Re: Scaling document truncates bottom-most page object
                  Laubender Adobe Community Professional & MVP

                  @Bob – There are some problems with scaling objects:

                   

                  0. There might be rounding errors!

                   

                  1. For text frames there is a mimimum size you have to consider:
                  a text frame cannot be smaller than 3 points in either direction (this is is a limition Adobe should take care for in a future version of InDesign).

                   

                   

                  2. Anchored text frames: you have to take care for the x- and y-offset related to the anchor when scaling.

                  Apply the scaling factor there as well.

                   

                  OR (as I realised when experimenting with MSOs (multi state objects)):

                  transform every page item to one big MSO. X- and y-offsets related to anchors of anchored text frames will be taken into account when scaling a MSO.

                   

                  But this seems to be bad advice, because every mother object that holds an anchored text frame will inherit the scale factor. Surprisingly the anchored text frames will not inherit the scale factor (as my quick and not overly thorough testing showed).

                   

                  You might think, o.k., let's redefine scaling of every mother object that holds an anchored text frame to 100%, but that will not translate  the x- and y-offset related to the anchored text frames and you end up with changing the x- and y-offset of anchored text frames after.

                   

                   

                   

                  3. In my testing with InDesign CS5.5 I could  provoke the "object extends beyond the pasteboard" error when using a (reasonable) large number as scaling factor, say "10", with an A4 page (210 x 297 mm). To circumvent that problem I scaled in two steps: factor 5 and then factor 2. No error occured then. Strange…

                   

                  Additionally:

                  1. be aware that the page margins do not scale automatically. Same goes for the positioning of guides.
                  2. did we speak of master pages and master page items? No? Take those into account as well.


                  Uwe

                  1 person found this helpful
                  • 6. Re: Scaling document truncates bottom-most page object
                    bobhopfner Level 1

                    Here's the next problem I am encountering. For some reason now it seems that my grep styles are not scaling, and not uniformly either. I have a price field where \$, \. (decimal) and the dollars and cents are all governed by grep styles except that now for some reason they are not scaling uniformly, the $ and cents remain at the size set by the grep style but the dollars and the decimal scale as intended. I am at a loss as to why this would happen.

                     

                    thanks,

                    Bob

                    • 7. Re: Scaling document truncates bottom-most page object
                      bobhopfner Level 1

                      It seems like setting the preference "Adjust Scaling Factor" instead of "Apply Scaling to Content" fixes this but I don't understand the difference. I thought I needed the latter.

                       

                      thanks,

                      Bob

                      • 8. Re: Scaling document truncates bottom-most page object
                        bobhopfner Level 1

                        If I understand the InDesign help file, "adjust scaling percentage" should just display the scaling of an object vs. showing it at 100% after the scale. Why does this have an effect on the actual scaling of an object?

                         

                        Is this a bug?

                        • 9. Re: Scaling document truncates bottom-most page object
                          bobhopfner Level 1

                          Another new wrinkle, so using "Adjust scaling percentage" on the server renders everything proportionally except the decimal, it now seems tied to the character style given to it by the GREP style.

                           

                          Is there any difference between transform() and resize()??

                           

                          thanks,

                          Bob