#target framemaker; /**************************************************************************/ /* */ /* practice innovation */ /* Copyright 2011 */ /* All Rights Reserved */ /* */ /**************************************************************************/ /* * Program Name: * << Delete Empty Pages >> * * Author: * Markus Wiedenmaier (markus.wiedenmaier@practice-innovation.de) * created: 20.11.2011 * * License * MIT License (http://www.practice-innovaton.de/wiki/SWATMITLICENSE) * * General Description: * * - Deletes all trailing empty pages in a document, when it is saved. Standard FM function only deletes default right and left pages * - Configurable if last page in a double sided layout is kept or also deleted * - Configuration if a specific master page is asigned to the last empty page in a double sided layout * **************************************************************************/ //!NOTIFICATION=5 // ======================================== // Script Configuration // ======================================== var swatCheckDoubleSideLayout = true ; //true => keeps and odd page count; false=> deletes all empty page var swatMasterPageNameForLastPage = ""; //if last page is empty (swatCheckDoubleSideLayout=true) set a specific master page for the last page (give name of the specific master page) //get BodyPage object frist, to enhance Doc and BodyPage class app.ActiveDoc.FirstBodyPageInDoc; // ======================================== // FM ES Object Extensions // ======================================== Doc.prototype.SWATDeleteEmptyPages = function() { if (this.ObjectValid()==false) return ; if (this.PageRounding != Constants.FV_PR_DEL_EMPTY) return ; //don't delete any pages, because of document setting var lastBodyPage = this.LastBodyPageInDoc; while (lastBodyPage.IsEmpty()) { //this.FirstPageVerso : false = Right Page; rigth: Left Page //don't delete left (or right) page in a double side layout, if previous page isn't empty! if (swatCheckDoubleSideLayout==true && this.DocIsDoubleSided==true && lastBodyPage.PageIsRecto==this.FirstPageVerso &&lastBodyPage.PagePrev.IsEmpty()==false) { //Set a spefic master page if last page is kept empty if (typeof(swatMasterPageNameForLastPage) != 'undefined' && swatMasterPageNameForLastPage!="") { lastBodyPage.PageBackground = Constants.FV_BGD_OTHER; lastBodyPage.MasterPage = swatMasterPageNameForLastPage; } return ; } lastBodyPage.Delete() ; lastBodyPage = this.LastBodyPageInDoc; } } BodyPage.prototype.IsEmpty = function() { if (this.ObjectValid()==false) return false ; var pageFrame = this.PageFrame; var graphic = pageFrame.FirstGraphicInFrame; while (graphic.ObjectValid()) { var nextGraphic = graphic.NextGraphicInFrame; if (graphic.type != Constants.FO_TextFrame) { graphic = nextGraphic; continue ; } if (graphic.FirstPgf.ObjectValid() || graphic.FirstAFrame.ObjectValid() || graphic.FirstCell.ObjectValid() || graphic.FirstFn.ObjectValid() ) { return false ; //Page isn't empty } graphic = nextGraphic; } return true ; //BodyPage is empty } // ======================================== // calling functionality // ======================================== app.ActiveDoc.SWATDeleteEmptyPages ();