code: public Graphics2D renderContent()
      {
          View view = null;
          ViewFactory factory = getEditorKit().getViewFactory();
          if (factory instanceof SwingBoxViewFactory)
          {
              view = ((SwingBoxViewFactory) factory).getViewport();
          }
  
          if (view != null)
          {
              int w = (int) view.getPreferredSpan(View.X_AXIS);
              int h = (int) view.getPreferredSpan(View.Y_AXIS);
  
              Rectangle rec = new Rectangle(w, h);
  
              BufferedImage img = new BufferedImage(w, h,
                      BufferedImage.TYPE_INT_RGB);
              Graphics2D g = img.createGraphics();
              g.setClip(rec);
              view.paint(g, rec);
  
              return g;
          }
  
          return null;
      }
docs: Renders current content to graphic context, which is returned. May return
  null;
  
  @return the Graphics2D context
  @see Graphics2D