docs: function(pageCount, graph, pageFormat, border)
  	{
  		if (pageCount < 1)
  		{
  			// We can't work with less than 1 page, return no scale
  			// change
  			return 1;
  		}
  		
  		pageFormat = (pageFormat != null) ? pageFormat : mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  		border = (border != null) ? border : 0;
  		
  		var availablePageWidth = pageFormat.width - (border * 2);
  		var availablePageHeight = pageFormat.height - (border * 2);
  
  		// Work out the number of pages required if the
  		// graph is not scaled.
  		var graphBounds = graph.getGraphBounds().clone();
  		var sc = graph.getView().getScale();
  		graphBounds.width /= sc;
  		graphBounds.height /= sc;
  		var graphWidth = graphBounds.width;
  		var graphHeight = graphBounds.height;
  
  		var scale = 1;
  		
  		// The ratio of the width/height for each printer page
  		var pageFormatAspectRatio = availablePageWidth / availablePageHeight;
  		// The ratio of the width/height for the graph to be printer
  		var graphAspectRatio = graphWidth / graphHeight;
  		
  		// The ratio of horizontal pages / vertical pages for this 
  		// graph to maintain its aspect ratio on this page format
  		var pagesAspectRatio = graphAspectRatio / pageFormatAspectRatio;
  		
  		// Factor the square root of the page count up and down 
  		// by the pages aspect ratio to obtain a horizontal and 
  		// vertical page count that adds up to the page count
  		// and has the correct aspect ratio
  		var pageRoot = Math.sqrt(pageCount);
  		var pagesAspectRatioSqrt = Math.sqrt(pagesAspectRatio);
  		var numRowPages = pageRoot * pagesAspectRatioSqrt;
  		var numColumnPages = pageRoot / pagesAspectRatioSqrt;
  
  		// These value are rarely more than 2 rounding downs away from
  		// a total that meets the page count. In cases of one being less 
  		// than 1 page, the other value can be too high and take more iterations 
  		// In this case, just change that value to be the page count, since 
  		// we know the other value is 1
  		if (numRowPages < 1 && numColumnPages > pageCount)
  		{
  			var scaleChange = numColumnPages / pageCount;
  			numColumnPages = pageCount;
  			numRowPages /= scaleChange;
  		}
  		
  		if (numColumnPages < 1 && numRowPages > pageCount)
  		{
  			var scaleChange = numRowPages / pageCount;
  			numRowPages = pageCount;
  			numColumnPages /= scaleChange;
  		}		
  
  		var currentTotalPages = Math.ceil(numRowPages) * Math.ceil(numColumnPages);
  
  		var numLoops = 0;
  		
  		// Iterate through while the rounded up number of pages comes to
  		// a total greater than the required number
  		while (currentTotalPages > pageCount)
  		{
  			// Round down the page count (rows or columns) that is
  			// closest to its next integer down in percentage terms.
  			// i.e. Reduce the page total by reducing the total
  			// page area by the least possible amount
  
  			var roundRowDownProportion = Math.floor(numRowPages) / numRowPages;
  			var roundColumnDownProportion = Math.floor(numColumnPages) / numColumnPages;
  			
  			// If the round down proportion is, work out the proportion to
  			// round down to 1 page less
  			if (roundRowDownProportion == 1)
  			{
  				roundRowDownProportion = Math.floor(numRowPages-1) / numRowPages;
  			}
  			if (roundColumnDownProportion == 1)
  			{
  				roundColumnDownProportion = Math.floor(numColumnPages-1) / numColumnPages;
  			}
  			
  			// Check which rounding down is smaller, but in the case of very small roundings
  			// try the other dimension instead
  			var scaleChange = 1;
  			
  			// Use the higher of the two values
  			if (roundRowDownProportion > roundColumnDownProportion)
  			{
  				scaleChange = roundRowDownProportion;
  			}
  			else
  			{
  				scaleChange = roundColumnDownProportion;
  			}
  
  			numRowPages = numRowPages * scaleChange;
  			numColumnPages = numColumnPages * scaleChange;
  			currentTotalPages = Math.ceil(numRowPages) * Math.ceil(numColumnPages);
  			
  			numLoops++;
  			
  			if (numLoops > 10)
  			{
  				break;
  			}
  		}
  
  		// Work out the scale from the number of row pages required
  		// The column pages will give the same value
  		var posterWidth = availablePageWidth * numRowPages;
  		scale = posterWidth / graphWidth;
  		
  		// Allow for rounding errors
  		return scale * 0.99999;
  	}