valerybokov commented on pull request #107:
URL: https://github.com/apache/pdfbox/pull/107#issuecomment-1046265181


   I have one little proposition. The method 
PDPage.getAnnotations(AnnotationFilter) returns instance of COSArrayList. The 
PageDrawer uses it inside drawPage method (reading). We able to create 
additional method to reduce memory usage for this case. Method:
   
   //The idea: don't use COSArrayList because it is expensive. Use ArrayList.
   
       /**
        * This will return a list of the annotations for this page.
        *
        * @param annotationFilter the annotation filter provided allowing to 
filter out specific annotations
        * @return List of the PDAnnotation objects, never null.
        *
        * @throws IOException If there is an error while creating the 
annotation list.
        */
       public List<PDAnnotation> getAnnotationsList(AnnotationFilter 
annotationFilter) throws IOException
       {
           COSArray annots = page.getCOSArray(COSName.ANNOTS);
           if (annots == null)
           {
               return Collections.EMPTY_LIST;
           }
           List<PDAnnotation> actuals = new ArrayList<>();
           for (int i = 0; i < annots.size(); i++)
           {
               COSBase item = annots.getObject(i);
               if (item != null)
               {
                   PDAnnotation createdAnnotation = 
PDAnnotation.createAnnotation(item);
                   if (annotationFilter.accept(createdAnnotation))
                   {
                       actuals.add(createdAnnotation);
                   }
               }
           }
           return actuals;
       }
   
   Maybe, this additional method will be better if you use it instead of 
PDPage.getAnnotations() for some cases. The code:
       public List<PDAnnotation> getAnnotationsList() throws IOException
       {
        return getAnnotationsList(annotation -> true);
       }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to