@@ -67,19 +67,30 @@ public BufferedImage takeScreenshot() {
6767 }
6868
6969 public BufferedImage takeScreenshotEntirePage () {
70- BufferedImage combinedImage = new BufferedImage (this .getDocWidth (), this .getDocHeight (), BufferedImage .TYPE_INT_ARGB );
70+ final int _docWidth = this .getDocWidth ();
71+ final int _docHeight = this .getDocHeight ();
72+ BufferedImage combinedImage = new BufferedImage (_docWidth , _docHeight , BufferedImage .TYPE_INT_ARGB );
7173 Graphics2D g = combinedImage .createGraphics ();
72- int horizontalIterations = (int ) Math .ceil (((double ) this .getDocWidth ()) / this .getViewportWidth ());
73- int verticalIterations = (int ) Math .ceil (((double ) this .getDocHeight ()) / this .getViewportHeight ());
74+ int _viewportWidth = this .getViewportWidth ();
75+ int _viewportHeight = this .getViewportHeight ();
76+ final int scrollBarMaxWidth = 40 ; // this is probably too high, but better to be safe than sorry
77+
78+ if (_viewportWidth < _docWidth || (_viewportHeight < _docHeight && _viewportWidth - scrollBarMaxWidth < _docWidth ))
79+ _viewportHeight -=scrollBarMaxWidth ; // some space for a scrollbar
80+ if (_viewportHeight < _docHeight )
81+ _viewportWidth -=scrollBarMaxWidth ; // some space for a scrollbar
82+
83+ int horizontalIterations = (int ) Math .ceil (((double ) _docWidth ) / _viewportWidth );
84+ int verticalIterations = (int ) Math .ceil (((double ) _docHeight ) / _viewportHeight );
7485 outer_loop :
7586 for (int j = 0 ; j < verticalIterations ; j ++) {
76- this .scrollTo (0 , j * this . getViewportHeight () );
87+ this .scrollTo (0 , j * _viewportHeight );
7788 for (int i = 0 ; i < horizontalIterations ; i ++) {
78- this .scrollTo (i * this . getViewportWidth (), this . getViewportHeight () * j );
89+ this .scrollTo (i * _viewportWidth , _viewportHeight * j );
7990 wait (scrollTimeout );
8091 Image image = takeScreenshot ();
8192 g .drawImage (image , this .getCurrentScrollX (), this .getCurrentScrollY (), null );
82- if (this . getDocWidth () == image .getWidth (null ) && this . getDocHeight () == image .getHeight (null )){
93+ if (_docWidth == image .getWidth (null ) && _docHeight == image .getHeight (null )){
8394 break outer_loop ;
8495 }
8596 }
0 commit comments