37 Replies Latest reply on Dec 16, 2016 8:34 AM by Gonterman1201

    apply master page after page size change

    Gonterman1201 Level 1

      I'm having trouble. I am changing the page size to crop then exporting to jpeg. Then I change the page size back works great but the master page becomes disconnected. I can't figure out how to apply it again.

      I am trying something like this

      var myDocument=app.activeDocument;
      var curPage = myDocument.pages[1];
      
      X=curPage.appliedMaster;
      

      This does nothing.

      A point in the right direction would help alot thanks.

      Brett G

        • 1. Re: apply master page after page size change
          Laubender Adobe Community Professional & MVP

          Can't you store the applied master to a variable before cropping and apply it again after resizing the page?

          Also check the value for layoutRule of the applied master. There are 7 options to choose from.

           

          Regrads,
          Uwe

          • 2. Re: apply master page after page size change
            Gonterman1201 Level 1

            I think you could make that a variable. I need to know how to apply it.

            • 3. Re: apply master page after page size change
              Laubender Adobe Community Professional & MVP

              See the DOM documentation for the Page Object and look for the appliedMaster property.

              InDesign ExtendScript API (11.0)

              • 4. Re: apply master page after page size change
                Gonterman1201 Level 1

                Okay. Here is what I think I'm going to do. Because the master stays applied to the even pages of the spread. I can use that master and apply it to the odd pages. This is how I'm going to do it.

                var myDocument=app.activeDocument;
                var curPage = myDocument.pages[0];
                var curPage1 = myDocument.pages[1];
                curPage1.appliedMaster=curPage.appliedMaster;///here is the magic////////
                
                • 5. Re: apply master page after page size change
                  Laubender Adobe Community Professional & MVP

                  If it's working for you, it's working for you. :-)
                  I cannot comment on this, because I cannot not see your document.

                   

                  Best,

                  Uwe

                  • 6. Re: apply master page after page size change
                    Gonterman1201 Level 1

                    The problem I am having now is with the applied master. On the odd page of the spread the master is not getting applied correctly. The master is applying on top of the even page. I think it may be a mater of master applied to spread vs. page.

                    Do you know how to apply a master to spread? Or allpage items?

                    • 7. Re: apply master page after page size change
                      Gonterman1201 Level 1

                      Okay here is what i think I need to do in the script. Because I have done it manually and it works. First change applied master to none all page items. This removes the master from both pages of the spread. Then apply the master to that page after the page has changed choosing keep current size. Any ideas on how to do this in the script?

                      • 8. Re: apply master page after page size change
                        Laubender Adobe Community Professional & MVP

                        Hi Brett,
                        as I already said: without a test document at hand I cannot help here much.
                        Please, make one available. Best through your Dropbox account and post the link here.
                        Then I am able to see into the issues.

                         

                        Regards,
                        Uwe

                        • 9. Re: apply master page after page size change
                          Gonterman1201 Level 1

                          myPage.reframe(CoordinateSpaces.INNER_COORDINATES, [[myX1, myY1], [myX2, myY2]]);

                          ///////EXPORT AFTER THIS THEN RETURN TO NORMAL////////////////

                          if(differ!=0){

                                          curPage1[i].appliedMaster=null;

                                          curPage=curPage1[i-1];

                                          curPage.appliedMaster=null;

                                          curPage1[i].appliedMaster = app.activeDocument.masterSpreads.itemByName("A-Document Master"); 

                                         

                                      }

                          I just need to know how in script do you say Master Page Size conflict choose keep current page size.

                          It seems to default to "Use master page size. The test document is just two pages. It has content that goes across the spread on the master page.

                          • 10. Re: apply master page after page size change
                            Laubender Adobe Community Professional & MVP

                            Because I cannot see into your document, the following is pure guesswork. And you did not post a screenshot.

                            I think, at least you could have provided an empty document in the state after the transform of the page was reverted.

                             

                            I cannot find an option in the scripting DOM to do "Keep current page size".

                            So I only have a workaround for you. Could work with your document or not. Don't know…

                             

                            Try to duplicate the transformed and reverted spread as a master spread and apply that.
                            Then there should be no conflict.

                             

                            A document with some resized pages by the Page Tool of the UI.
                            I know, you said you redid the transformation of the page, so this is only for clarifying my point:

                             

                            Before running the snippet below:

                             

                            BEFORE-DuplicateSpreadAsMaster.png

                             

                             

                            app.documents[0].spreads[0].duplicate( LocationOptions.AFTER , app.documents[0].masterSpreads[0] );
                            app.documents[0].masterSpreads[1].pageItems.everyItem().remove();
                            app.documents[0].spreads[0].appliedMaster = app.documents[0].masterSpreads[1];
                            

                             

                             

                            After running the snippet above:

                             

                            AFTER-DuplicateSpreadAsMaster.png

                             

                            Do not assign the master [None] before.

                             

                            Regards,
                            Uwe

                            • 11. Re: apply master page after page size change
                              Kai Rübsamen Level 4

                              Ähm, just to say it:

                               

                              If you want to export something on your page, there is no need to crop the page. Simply group the objects and export the selection.

                               

                              Kai

                              • 12. Re: apply master page after page size change
                                Laubender Adobe Community Professional & MVP

                                True. However, that's not my cup of tea…
                                Let's assume the whole page is needed, because objects from the applied master should be exported as well.
                                Or that a PDF or an EPS should be exported.

                                 

                                Uwe

                                • 13. Re: apply master page after page size change
                                  Kai Rübsamen Level 4

                                  OK .

                                   

                                  I did not read everything here, but: If this task is complicated, why not save the document, do all your stuff and close it without saving it?

                                  • 14. Re: apply master page after page size change
                                    Laubender Adobe Community Professional & MVP

                                    That's a valid workaround.
                                    But I'm after solving or avoiding the core problem.
                                    And I have no clue what Brett is exactly doing before he tries to apply the master.


                                    Maybe he has to work with two transformation matrices instead of using reframe().

                                     

                                    Let's see what he is saying…

                                     

                                    Uwe

                                    • 15. Re: apply master page after page size change
                                      Gonterman1201 Level 1

                                      So if I remove all the applied masters one at a time and then replace them it works except for the fact that when they get applied it resizes to master instead of remaining the same. Also if I remove as spread and apply as spread. I get a duplicate master on the even page side. I really appreciate your input. I am also wondering if I could just reframe the master?

                                      • 16. Re: apply master page after page size change
                                        Laubender Adobe Community Professional & MVP

                                        Brett,

                                        could you please explain step-by-step what you like to do?
                                        From A to Z. And provide document samples for every step. Code samples as well.

                                         

                                        I really have no idea what's going on.

                                        Your reframe() function obviously in not bringing back the old state of the page.

                                        And that's the culprit.

                                         

                                        Thank you,
                                        Uwe

                                        • 17. Re: apply master page after page size change
                                          Gonterman1201 Level 1

                                          var myDocument=app.activeDocument;

                                          var docName=my Docu.name;

                                          docName=docName.slice(0,-12);

                                           

                                          var curPage1 = myDocument.pages;

                                          for (var i = 0; i < curPage1.length; i++) {

                                          app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;

                                          app.jpegExportPreferences.exportResolution = 170;///////////800 size

                                          app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

                                           

                                          nPgName=curPage1[i].name;

                                           

                                           

                                          if ((nPgName.length<3)&&(nPgName.length>1)){

                                                          nPgName=("0"+nPgName);

                                                          }

                                                       if(nPgName.length<2){

                                                          nPgName=("00"+nPgName);

                                                          }

                                          /////////////////////////////////////////////////

                                          document.viewPreferences.rulerOrigin = RulerOrigin.SPINE_ORIGIN;

                                          document.zeroPoint = [0, 0];

                                           

                                          var myPage = curPage1.item(i);

                                          //Y=myPage.marginPreferences.bottom=72;

                                              pnum = curPage1[i].name;

                                              differ=pnum%2;

                                          var myBounds = myPage.bounds;

                                           

                                          var myY1 = myBounds[0]+12.225;

                                          if(differ==0){

                                              var myX1 = myBounds[1]+12.225;

                                              var myX2 = myBounds[3];

                                              }

                                          else{var myX1 = myBounds[1];var myX2 = myBounds[3]-12.225;}

                                          var myY2 = myBounds[2]-119;

                                           

                                          myPage.reframe(CoordinateSpaces.INNER_COORDINATES, [[myX1, myY1], [myX2, myY2]]);

                                          ///////EXPORT AFTER THIS THEN RETURN TO NORMAL////////////////

                                           

                                          if(differ!=0){

                                                          curPage1[i].appliedMaster=null;

                                                          curPage=curPage1[i-1];

                                                          curPage.appliedMaster=null;

                                                          //curPage1[i].appliedMaster=curPage.appliedMaster;/////is currently applying the master of page even

                                                          curPage1[i].appliedMaster = app.activeDocument.masterSpreads.itemByName("A-Document Master"); 

                                                          //alert(curPage.name+"  "+curPage1[i].name);

                                                         

                                                      }

                                          ////////////////////////////////////////////////

                                           

                                          var poop=app.jpegExportPreferences.pageString =curPage1[i].name.toString();

                                           

                                           

                                           

                                               myFilePath="/Volumes/Testing/binuscan Test/BookViewerTest/"+docName+nPgName+".jpg";

                                                  myFile=new File(myFilePath);   

                                          myDocument.exportFile(ExportFormat.JPG, myFile);

                                          myPage.reframe(CoordinateSpaces.INNER_COORDINATES, [[myBounds[1], myBounds[0]], [myBounds[3], myBounds[2]]]);

                                          //pnum = curPage1[i].name;

                                                      //differ=pnum%2;

                                                     

                                                      if(differ!=0){

                                                          curPage=curPage1[i-1];

                                                          curPage1[i].appliedMaster=curPage.appliedMaster;

                                                          //curPage1[i].appliedMaster = app.activeDocument.masterSpreads.itemByName("A-Document Master"); 

                                                          //alert(curPage.name+"  "+curPage1[i].name);

                                                         

                                                      }

                                           

                                          }

                                           

                                            

                                          • 18. Re: apply master page after page size change
                                            Gonterman1201 Level 1

                                            1.Step one change page size to crop document.

                                            2. Depends if its an odd page. I want to export to jpg. But indesign disconnects the master on the odd page side.

                                                 So then I have to re apply the master.

                                            3.Export the jpeg

                                            4. Return everything back to normal. I am changing the page size again and re applying the master.

                                            • 19. Re: apply master page after page size change
                                              Gonterman1201 Level 1

                                              Can you change the master page size?

                                              • 20. Re: apply master page after page size change
                                                Gonterman1201 Level 1

                                                I am googling. I found this thread which may account for the problem I am having.

                                                Master Page Items Moving on Custom-Sized Page

                                                • 21. Re: apply master page after page size change
                                                  Gonterman1201 Level 1

                                                  I was just taking a look at LayoutRuleOptions and it looks like this is a parameter of createAlternateLayout. The thing I don't understand is why InDesign applies the master on the facing page side to the first page in the spread after you reframe.

                                                  I am considering pulling everything off the master and putting it on the page before I reframe. Thoughts?

                                                  • 22. Re: apply master page after page size change
                                                    Gonterman1201 Level 1

                                                    Okay for those of you who have grown tired of this long post I am sorry. I believe I have gotten closer to solving my problem. The items on the master page that are moving are moving because they are on the pasteboard. And InDesign does not like this apparently when resizing. If I fix the pasteboard issue I should not have to re apply the master. I will let you know the final outcome when I finish testing.

                                                    • 23. Re: apply master page after page size change
                                                      Skemicle Level 3

                                                      In the pages panel could you not right click the master page item and go to Panel Options and set the Resize field to "Pages Fixed"? I haven't messed with this but it seems like that should produce the desired result. Just a theory.

                                                      • 24. Re: apply master page after page size change
                                                        Gonterman1201 Level 1

                                                        I'm going in a different direction unless anyone has a better idea.

                                                        first I am going to group all of the master page items together. Then apply master null to the odd page removing the master from that page. However the master will continue to show because it is grouped with the first page.

                                                        Then export to jpeg.

                                                        Then revert back to original.

                                                        • 25. Re: apply master page after page size change
                                                          Gonterman1201 Level 1

                                                          So even though I say

                                                          measure=app.scriptPreferences.measurementUnit = MeasurementUnits.PICAS;

                                                          reframe reads it in points.

                                                          and even though I say

                                                          document.viewPreferences.rulerOrigin = RulerOrigin.SPINE_ORIGIN;

                                                          it reads as a spread.

                                                          That "54" you see up there on the ruler that's the end of my document when my document is showing from the spine.

                                                          But the bounds is reading in Picas by the way the whole damn spread.

                                                          But reframe is going to use points. Can anyone explain this???

                                                          • 26. Re: apply master page after page size change
                                                            Laubender Adobe Community Professional & MVP

                                                            All transform functions work with Points only.
                                                            Or nearly all? I have to check that…

                                                            • 27. Re: apply master page after page size change
                                                              Gonterman1201 Level 1

                                                              So I was using bounds as a basis for my reframe. However bounds can be any measurement and be measured from Spine, Page, or Spread. So if you are using reframe make sure that your measurements are in points either in the script or change preferences to points. Then also set Ruler per Spread. This was accounting for the shift in the applied master page.

                                                              document.viewPreferences.rulerOrigin =RulerOrigin.SPREAD_ORIGIN

                                                              measure=app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

                                                              • 29. Re: apply master page after page size change
                                                                Gonterman1201 Level 1

                                                                well today is a new day. Nothing has changed except I feel like i am back to square one because its not working again.

                                                                • 30. Re: apply master page after page size change
                                                                  Gonterman1201 Level 1

                                                                  No one wants to be done with this more than me. This is a long post. So I really thought I solved the problem switching to points and changing to read from spread, so smart. Not really. I've done this so many times I had changed the file. Giving me a false positive. So the script changes the page by using reframe. When it finishes the right side of the master gets applied to the left. Then if I apply master to each page individually then reapply the master as a spread. And I have that as my starting point. I can run the same script every time and it will apply the master just fine. The problem is I have no idea why this happens. Does anyone have experience reframing pages? I kind of hate the idea of having to loop back around twice.

                                                                  • 31. Re: apply master page after page size change
                                                                    Kai Rübsamen Level 4

                                                                    Just to say it again: Why do you ignore my comment a week ago? In my opinion there is really no need to do all this stuff...

                                                                    • 32. Re: apply master page after page size change
                                                                      Gonterman1201 Level 1

                                                                      I am doing this to crop. If the items hang outside and i group what will the bounds be?

                                                                      • 33. Re: apply master page after page size change
                                                                        Kai Rübsamen Level 4

                                                                        What do you mean with 'outside'? If you group your elements you can then just export the selection.

                                                                         

                                                                        If you need also elements from a masterpage, you could separate elements from the master.

                                                                        If all this stuff does not work, you could save your doc, did your masterpage thing and close the document without saving.

                                                                         

                                                                        So: Provide a example before/after (not only screenshots) and don’t make things so complicated ;-)

                                                                        • 34. Re: apply master page after page size change
                                                                          Marc Autret Level 4

                                                                          Hi colleagues,

                                                                           

                                                                          OK, my two pennies on this topic.

                                                                           

                                                                          Reframing pages is always a dangerous sport, especially in a facing-page document. Indeed, since those facing pages are not supposed to undergo any 'move' along the X-axis, each time a reframe occurs that involves changing X coordinates, many unexpected things may happen behind the scene. The page geometry is modified, its translation attributes are readjusted in its transformation matrix, the relationship with the master spread may be somehow altered, and as discussed in other threads bugs or issues with the masterPageTransform property may occur, weird shifts that seem unrepairable, not to mention the options related to layout rules, and so on.

                                                                           

                                                                          So it's hard to design a script that works in all environments, all versions, all configurations. There is always an obscure preference that someone has activated, or disabled, which interacts with the whole system and ruins all our effort.

                                                                           

                                                                          There is at least one law that we have learned from experience: DO NEVER TRUST the page.bounds property. If you attempt to reframe pages, assuming that no better solution has been found, try to work with properly resolved coordinates—myPage.resolve(…)—and stick to the tools that coordinate spaces and transformation provide. Here is an attempt to fix your problem on this basis.

                                                                           

                                                                          Try this:

                                                                           

                                                                          // YOUR SETTINGS
                                                                          // =====================================
                                                                          
                                                                          // Values required IN POINTS (negative numbers allowed, for increasing the area.)
                                                                          // ---
                                                                          const CROP_SIDE   = 12.225/*pt*/,
                                                                                CROP_TOP    = 12.225/*pt*/,
                                                                                CROP_BOTTOM = 100/*pt*/;
                                                                          
                                                                          // Export options, etc.
                                                                          // ---
                                                                          const DOC_NAME_MAX_SIZE = 12,
                                                                                OUT_PATH = "/Volumes/Testing/binuscan Test/BookViewerTest/";
                                                                          
                                                                          const JPG_EXPORT_PREFS = {
                                                                              jpegQuality:      +JPEGOptionsQuality.high,
                                                                              exportResolution: 170,
                                                                              jpegExportRange:  +ExportRangeOrAllPages.exportRange,
                                                                              };
                                                                          
                                                                          (function exportPageAreas()
                                                                          // =====================================
                                                                          // Should support the tricky 'facing-page' case, including when
                                                                          // pages have different sizes, and whatever the rulerOrigin mode.
                                                                          {
                                                                              // Boring constants.
                                                                              // ---
                                                                              const CS_INNER = +CoordinateSpaces.INNER_COORDINATES,
                                                                                    CS_SPREAD = +CoordinateSpaces.SPREAD_COORDINATES,
                                                                                    TL = +AnchorPoint.TOP_LEFT_ANCHOR,
                                                                                    BR = +AnchorPoint.BOTTOM_RIGHT_ANCHOR;
                                                                          
                                                                              const LEFT_HAND = +PageSideOptions.LEFT_HAND;
                                                                          
                                                                              // Context validation.
                                                                              // ---
                                                                              var doc = app.properties.activeDocument;
                                                                              if( !doc ){ alert( "No document!" ); return; }
                                                                          
                                                                              // Export prefs.
                                                                              // ---
                                                                              const EXP_JPG = +ExportFormat.JPG,
                                                                                    JEP = app.jpegExportPreferences,
                                                                                    filePrefix = OUT_PATH + doc.properties.name.substr(-DOC_NAME_MAX_SIZE);
                                                                              JEP.properties = JPG_EXPORT_PREFS;
                                                                          
                                                                              // Last variables.
                                                                              // ---
                                                                              var pages = doc.pages.everyItem().getElements(),
                                                                                  pg, pgName,
                                                                                  dxLeft, dxRight,
                                                                                  xyTL, xyBR;
                                                                          
                                                                              // Loop.
                                                                              // ---
                                                                              while( pg=pages.pop() )
                                                                              {
                                                                                  // Page corners coords in the parent space.
                                                                                  // (Note: Do Never Trust page.bounds!)
                                                                                  // ---
                                                                                  xyTL = pg.resolve(TL, CS_SPREAD)[0];
                                                                                  xyBR = pg.resolve(BR, CS_SPREAD)[0];
                                                                          
                                                                                  // Opposite corners => reframe.
                                                                                  // ---
                                                                                  dxLeft  = LEFT_HAND == +pg.side ? CROP_SIDE : 0;
                                                                                  dxRight = dxLeft ? 0 : CROP_SIDE;
                                                                          
                                                                                  pg.reframe( CS_SPREAD,
                                                                                  [
                                                                                      [ xyTL[0]+dxLeft,  xyTL[1]+CROP_TOP ],
                                                                                      [ xyBR[0]-dxRight, xyBR[1]-CROP_BOTTOM ]
                                                                                  ]);
                                                                          
                                                                                  // Export.
                                                                                  // ---
                                                                                  JEP.pageString = pgName = pg.name;
                                                                                  doc.exportFile(EXP_JPG, new File(filePrefix+('00'+pgName).substr(-3)+'.jpg'));
                                                                          
                                                                                  // Restore page. Here we can't safely re-use [xyTL,xyBR] as it is,
                                                                                  // because the spread space origin *may* have moved during reframe.
                                                                                  // Therefore we need to formally reverse the calculation.
                                                                                  // ---
                                                                                  xyTL = pg.resolve(TL, CS_SPREAD)[0];
                                                                                  xyBR = pg.resolve(BR, CS_SPREAD)[0];
                                                                                  pg.reframe( CS_SPREAD,
                                                                                  [
                                                                                      [ xyTL[0]-dxLeft,  xyTL[1]-CROP_TOP ],
                                                                                      [ xyBR[0]+dxRight, xyBR[1]+CROP_BOTTOM ]
                                                                                  ]);
                                                                              }
                                                                              
                                                                              alert( 'Page areas have been successfully exported.' );
                                                                          
                                                                          })();
                                                                          

                                                                           

                                                                           

                                                                          May work or may fail… Who knows?

                                                                           

                                                                          @+

                                                                          Marc

                                                                          • 35. Re: apply master page after page size change
                                                                            Laubender Adobe Community Professional & MVP

                                                                            Gonterman1201 wrote:

                                                                            … Does anyone have experience reframing pages? I kind of hate the idea of having to loop back around twice.

                                                                             

                                                                            Hi Brett,

                                                                            if and only if you have a solution for reframing pages successfully and your real problems are the fact, that you cannot get back the original sizes and positions of the pages, why don't you simply:

                                                                             

                                                                            1. Reframe the pages

                                                                            2. Export to JPEG

                                                                            3. Close doc without saving.

                                                                            4. Open doc again

                                                                             

                                                                            var myDocument = app.documents[0];
                                                                            var fileOfDocument = File(myDocument.fullName);
                                                                            myDocument.save();
                                                                            
                                                                            /*
                                                                            Do your stuff here.
                                                                            */
                                                                            
                                                                            myDocument.close(SaveOptions.NO);
                                                                            app.open(fileOfDocument);
                                                                            

                                                                             

                                                                            I know, this sounds like cheating, but if it will help … ?! So what.

                                                                             

                                                                            Best,
                                                                            Uwe

                                                                            • 36. Re: apply master page after page size change
                                                                              Gonterman1201 Level 1

                                                                              I am amazed! Marc you are a genius. It looks at first glance to me that my problem may have been with bounds. I saw resolve in the sdk but had no idea how to use it. Everyone who sees this can crop away with ease.

                                                                              Thank you.

                                                                              Brett Gonterman

                                                                              • 37. Re: apply master page after page size change
                                                                                Gonterman1201 Level 1

                                                                                Cropping away with ease is not entirely true. There have been some bobbles. I am not sure why but there are files that crop up that have individual pages with some objects that still move. The problems that Marc talks about are real.