// // Copyright 2003 Point2 Technologies, Inc. // // Developer: Colin Bendell // // Description: // Inserts css page breaks based on the content being rendered. The behavior // traverses the document objects and looks for table entries. Each table is understood // to be a set of pages with a head and footer and the rows are the allowable page break // delimiters. Each table will force a page break at the end to prepare for the next table // block. // var PAGE_HEIGHT_OFFSET_PX = 11; //hack - print setup has a header and footer that factor into the calculation by 11 pixels var PAGE_HEIGHT = 11; var PAGE_WIDTH = 8.5; var PAGE_LEFT_MARGIN = 1; var PAGE_RIGHT_MARGIN = 1; var PAGE_TOP_MARGIN = 1; var PAGE_BOTTOM_MARGIN = .5; var DPI = 96; /** * Determines if the document is ready for page breaks to be calculated * then performs the page break calculations * * @param htmlObj the document to calculate the children. By default * this is the body element. Overload this method to calculate breaks * within another html element such as a div */ function calculateBreaks(htmlObj, breakRows) { if (breakRows == null) { breakRows = true; } if (htmlObj == null) { //htmlObj = ownerDocument.body; htmlObj = parent.document.body; } var img; //for (var i=0; i < ownerDocument.images.length; i++) for (var i=0; i < parent.document.images.length; i++) { //img = ownerDocument.images(i); img = parent.document.images(i); if (img.complete != true) { setTimeout(this.uniqueID + ".calculateBreaks(" + htmlObj.uniqueID + ")", 500); return; } } // first we calculate the height and width var calcHeight = Math.round((PAGE_HEIGHT - PAGE_TOP_MARGIN - PAGE_BOTTOM_MARGIN) * DPI) - PAGE_HEIGHT_OFFSET_PX; var calcWidth = Math.round((PAGE_WIDTH - PAGE_LEFT_MARGIN - PAGE_RIGHT_MARGIN) * DPI); var baseHeight; var segmentHeight; var tBody; var tBodyIndex; var row; var rowIndex; htmlObj = htmlObj.firstChild; while (htmlObj) { if (htmlObj.tagName == 'TABLE') { baseHeight = 0; if (htmlObj.tHead != null) { baseHeight = baseHeight + htmlObj.tHead.offsetHeight; htmlObj.tHead.style.display = "table-header-group"; } if (htmlObj.tFoot != null) { baseHeight = baseHeight + htmlObj.tFoot.offsetHeight; htmlObj.tFoot.style.display = "table-footer-group"; } segmentHeight = baseHeight; //page break before if( htmlObj.previousSibling != null ) { htmlObj.style.pageBreakBefore = "always"; } // set the width to fit the page htmlObj.width = calcWidth; if (breakRows) { for (tBodyIndex = 0; tBodyIndex < htmlObj.tBodies.length; tBodyIndex++) { tBody = htmlObj.tBodies[tBodyIndex]; for (rowIndex = 0; rowIndex < tBody.rows.length; rowIndex++) { row = tBody.rows[rowIndex]; if ((segmentHeight = segmentHeight + row.offsetHeight) > calcHeight) { row.style.pageBreakBefore = "always"; row.style.borderTop = "solid 1px black"; segmentHeight = row.offsetHeight + baseHeight; } } } } } htmlObj = htmlObj.nextSibling; } }