title: How can I get Images coordinates in pdf into JSONfile?
body: <p>I have coded creating html page included images extracting a page in pdf document.</p>
  
  <p>I had tried to extract images from pdf and then I succeeded to extract images from pdf and to apply the images to html page using PDFBox lib. but I did not extract image coordinates in html page.</p>
  
  <p>So searched how to extract image coordinates in pdf, I tried to extract image coordinates in pdf using PDFBox Library.</p>
  
  <p>Below code : </p>
  
  <pre><code>public static void main(String[] args) throws Exception
  {
      try
      {
          PDDocument document = PDDocument.load(
              "/Users/tmdtjq/Downloads/PDFTest/test.pdf" );
  
          PrintImageLocations printer = new PrintImageLocations();
          List allPages = document.getDocumentCatalog().getAllPages();
          for( int i=0; i&lt;allPages.size(); i++ )
          {
              PDPage page = (PDPage)allPages.get( i );
              int pageNum = i+1;
              System.out.println( "Processing page: " + pageNum );
              printer.processStream( page, page.findResources(),
                  page.getContents().getStream() );
          }
      }
      finally
      {
      }
  }
  
  protected void processOperator( PDFOperator operator, List arguments ) throws IOException
  {
      String operation = operator.getOperation();
      if( operation.equals( "Do" ) )
      {
          COSName objectName = (COSName)arguments.get( 0 );
          Map xobjects = getResources().getXObjects();
          PDXObject xobject = xobjects.get( objectName.getName() );
          if( xobject instanceof PDXObjectImage )
          {
              try
              {
                  PDXObjectImage image = (PDXObjectImage)xobject;
                  PDPage page = getCurrentPage();
                  Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
                  double rotationInRadians =(page.findRotation() * Math.PI)/180;
  
                  AffineTransform rotation = new AffineTransform();
                  rotation.setToRotation( rotationInRadians );
                  AffineTransform rotationInverse = rotation.createInverse();
                  Matrix rotationInverseMatrix = new Matrix();
                  rotationInverseMatrix.setFromAffineTransform( rotationInverse );
                  Matrix rotationMatrix = new Matrix();
                  rotationMatrix.setFromAffineTransform( rotation );
  
                  Matrix unrotatedCTM = ctm.multiply( rotationInverseMatrix );
                  float xScale = unrotatedCTM.getXScale();
                  float yScale = unrotatedCTM.getYScale();
                  float xPosition = unrotatedCTM.getXPosition();
                  float yPosition = unrotatedCTM.getYPosition();
  
                  System.out.println( "Found image[" + objectName.getName() + "] " +
                      "at " + xPosition + "," + yPosition +
                      " size=" + (xScale/100f*image.getWidth()) + "," + (yScale/100f*image.getHeight() ));
              }
              catch( NoninvertibleTransformException e )
              {
                  throw new WrappedIOException( e );
              }
          }
      }
  }
  </code></pre>
  
  <p>Outputs printing X,Y Positions in images is All 0.0, 0.0.</p>
  
  <p>I think because getGraphicsState() is method to return the graphicsState.</p>
  
  <p>But I want to get specific images coordinates applied to height,width of a PDF page in order to create html page.</p>
  
  <p>I think maybe it is solution to extract JSON from images coordinates in PDF.</p>
  
  <p>Please introduce image coordinates in PDF to JSON tool or suggest PDF Library.</p>
  
  <p>(Already I used pdf2json tool in FlexPaper. this tool extracts JSONfile including not images data but just texts data(content, coordinates, font..) from PDF page.)</p>