title: How to draw a filled rectangle in PDFBox?
body: <p>How to draw a filled rectangle using PDFBox?</p>
  
  <p>I just can't find the right function of the <a href="http://pdfbox.apache.org/" rel="nofollow">PDFBox API documentation</a>. </p>
  
  <p>I want to draw a filled rectangle under the first row of a table:</p>
  
  <pre><code>public static void drawTable(PDPage page, PDPageContentStream contentStream,
                              float y, float margin,
                              String[][] content) throws IOException {
  final int rows = content.length;
  final int cols = content[0].length;
  final float firstRowHeight = 160f;
  final float rowHeight = 20f;
  final float colWidth = 15f; //tableWidth/(float)cols;
  final float tableWidth = colWidth * cols; //page.findMediaBox().getWidth()-(2*margin);
  final float tableHeight = rowHeight * rows + firstRowHeight - rowHeight;    
  final float cellMargin= 5f;
  
  /*PDRectangle rectangle = new PDRectangle();
  rectangle.setLowerLeftX(10);
  rectangle.setLowerLeftY(10);
  rectangle.setUpperRightX(10);
  rectangle.setUpperRightY(10);
  page.setMediaBox(rectangle);
  page.setCropBox(rectangle);*/
  
  //draw the rows
  float nexty = y ;
  for (int i = 0; i &lt;= rows; i++) {
      contentStream.drawLine(margin,nexty,margin+tableWidth,nexty);
      if (i&lt;=0) {
      nexty-= firstRowHeight;
      } else {
      nexty-= rowHeight;
      }
  }
  
  //draw the columns
  float nextx = margin;
  for (int i = 0; i &lt;= cols; i++) {
      contentStream.drawLine(nextx,y,nextx,y-tableHeight);
      nextx += colWidth;
  }
  
  //now add the text
  contentStream.setFont(PDType1Font.HELVETICA_BOLD,8);
  
  float textx = margin+cellMargin;
  float texty = y-15;
  //int o = content.length;
  
  for(int i = 0; i &lt; content.length; i++){
      for(int j = 0 ; j &lt; content[i].length; j++){
          String text = content[i][j];
          contentStream.beginText();
          if (i&lt;=0) {
          contentStream.moveTextPositionByAmount(textx,texty-140);
          contentStream.setTextRotation(90*Math.PI*0.25,textx+5,texty-140);
          } else {
          contentStream.moveTextPositionByAmount(textx,texty);
          contentStream.setTextRotation(90*Math.PI*0.25,textx+5,texty-3); 
          }
          contentStream.drawString(text);
          contentStream.endText();
          textx += colWidth;
      }
      if (i&lt;=0) {
      texty-=firstRowHeight;
      } else {
      texty-=rowHeight;
      }
      textx = margin+cellMargin;
  }
  }
  </code></pre>