doc = PDDocument.load( args[0] );
List allPages = doc.getDocumentCatalog().getAllPages();
for( int i=0; i<allPages.size(); i++ )
{
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
PDPage page = (PDPage)allPages.get( i );
List annotations = page.getAnnotations();
//first setup text extraction regions
for( int j=0; j<annotations.size(); j++ )
{
PDAnnotation annot = (PDAnnotation)annotations.get( j );
if( annot instanceof PDAnnotationLink )
{
PDAnnotationLink link = (PDAnnotationLink)annot;
PDRectangle rect = link.getRectangle();
//need to reposition link rectangle to match text space
float x = rect.getLowerLeftX();
float y = rect.getUpperRightY();
float width = rect.getWidth();
float height = rect.getHeight();
int rotation = page.findRotation();
if( rotation == 0 )
{
PDRectangle pageSize = page.findMediaBox();
y = pageSize.getHeight() - y;
}
else if( rotation == 90 )
{
//do nothing