@Override
	public Object getPage(int pageNum, int width, int height) throws NoSuchPageException {
		if (pageNum < 1 || pageNum > pdffile.getNumPages())
			throw new NoSuchPageException();
		
		PDFPage page = pdffile.getPage(pageNum);
	        		
	    int sourceWidth = (int) page.getBBox().getWidth();
	    int sourceHeight = (int) page.getBBox().getHeight();
	    int thumbWidth, thumbHeight;
	    
	    if (sourceWidth > sourceHeight) {
	    	thumbWidth = width;
	    	thumbHeight = thumbWidth * sourceHeight / sourceWidth;
	    } else {
	    	thumbHeight = height;
	    	thumbWidth = thumbHeight * sourceWidth / sourceHeight;
	    }
	    
	    if (thumbWidth > width) {
	    	thumbWidth = width;
	    	thumbHeight = thumbWidth * sourceHeight / sourceWidth;
	    } else if (thumbHeight > height) {
	    	thumbHeight = height;
	    	thumbWidth = thumbHeight * sourceWidth / sourceHeight;
	    }
	
		final Rectangle2D rect = page.getBBox();
		
		Image img = page.getImage(
				thumbWidth, thumbHeight, //width & height
            	rect, // clip rect
            	null, // null for the ImageObserver
            	true, // fill background with white
            	true  // block until drawing is done
            );
		
	    return img;
	}