title: PDFBox: Inconsistent co-ordinate system, how do I draw a rectangle?
body: <p>This is the piece of code I have written to highlight texts in a PDF. This method takes PDDocument object, Page Number, Rectangle points(x,y,w,h), color and transparency. </p>
  
  <pre><code> public PDDocument highlightText(PDDocument document, Integer pageNo,Float[] rectPoints, Color color, Float transparency) throws Exception{
          /* highlighttext() takes document, page no and rectangle points[x,y,width,height] */
          try
          {
              PDPage page = document.getPage(pageNo);
              PDExtendedGraphicsState extendedGraphicsState = new PDExtendedGraphicsState();
              // Set the transparency/opacity
              extendedGraphicsState.setNonStrokingAlphaConstant(transparency);
  
              try(PDPageContentStream contents = new PDPageContentStream(document, page,AppendMode.APPEND,true)){
  
                  //use graphic state
                  contents.setGraphicsStateParameters(extendedGraphicsState);
                  contents.setNonStrokingColor(color);
                  //Rectangle points(x,y,w,h) - takes top left corner as (0,0) origin
                  contents.addRect(rectPoints[0], rectPoints[1], rectPoints[2], rectPoints[3]);
                  contents.fill();
              }
  
  
          } catch(Exception e) {
              e.printStackTrace();
              throw new Exception(e.getMessage());
          }
  
          return document;
      }
  </code></pre>
  
  <p><strong>Question:</strong>
  Issue here is with the Rectangle points (especially with Y co-ordinate)
  For a PDF I created using Microsoft Word Document (Using export), To draw a box, I gave the points [0,500,100,100], then rectangle was drawn considering that Origin was at <strong>BOTTOM-LEFT</strong> corner. Okay, that's great, right!</p>
  
  <p>For a PDF I created using Google Chrome (Using ctrl+p, save as file), To draw a box, I gave the points [0,500,100,100], now the rectangle was drawn at exactly opposite Y axis (considering that Origin is at <strong>TOP-LEFT</strong> corner). I am totally confused now, how addRect() takes the points. How do I fix this so that, if I give any kind of PDF, it takes any one location as Origin either bottom left or top left ? </p>