Search in sources :

Example 1 with AnnotationFilter

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter in project PdfBox-Android by TomRoush.

the class TestPDPageAnnotationsFiltering method validateAllFiltered.

@Test
public void validateAllFiltered() throws IOException {
    List<PDAnnotation> annotations = page.getAnnotations(new AnnotationFilter() {

        @Override
        public boolean accept(PDAnnotation annotation) {
            return false;
        }
    });
    Assert.assertEquals(0, annotations.size());
}
Also used : PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) AnnotationFilter(com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter) Test(org.junit.Test)

Example 2 with AnnotationFilter

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter in project PdfBox-Android by TomRoush.

the class TestPDPageAnnotationsFiltering method validateSelectedFew.

@Test
public void validateSelectedFew() throws IOException {
    List<PDAnnotation> annotations = page.getAnnotations(new AnnotationFilter() {

        @Override
        public boolean accept(PDAnnotation annotation) {
            return (annotation instanceof PDAnnotationLink || annotation instanceof PDAnnotationSquareCircle);
        }
    });
    Assert.assertEquals(2, annotations.size());
    Assert.assertTrue(annotations.get(0) instanceof PDAnnotationSquareCircle);
    Assert.assertTrue(annotations.get(1) instanceof PDAnnotationLink);
}
Also used : PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) AnnotationFilter(com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Test(org.junit.Test)

Example 3 with AnnotationFilter

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter in project PdfBox-Android by TomRoush.

the class COSArrayListTest method removeFromFilteredListByIndex.

@Test
public void removeFromFilteredListByIndex() throws Exception {
    // retrieve all annotations from page but the link annotation
    // which is 2nd in list - see above setup
    AnnotationFilter annotsFilter = new AnnotationFilter() {

        @Override
        public boolean accept(PDAnnotation annotation) {
            return !(annotation instanceof PDAnnotationLink);
        }
    };
    COSArrayList<PDAnnotation> cosArrayList = (COSArrayList<PDAnnotation>) pdPage.getAnnotations(annotsFilter);
    COSArray underlyingCOSArray = pdPage.getCOSObject().getCOSArray(COSName.ANNOTS);
    assertTrue("Filtered COSArrayList size shall be 2", cosArrayList.size() == 2);
    assertTrue("Underlying COSArray shall have 3 entries", underlyingCOSArray.size() == 3);
    assertTrue("Backed COSArray shall have 3 entries", cosArrayList.toList().size() == 3);
    // remove aCircle annotation
    int positionToRemove = 1;
    PDAnnotation toBeRemoved = cosArrayList.get(positionToRemove);
    assertTrue("We should remove the circle annotation", toBeRemoved.getSubtype().equals(PDAnnotationSquareCircle.SUB_TYPE_CIRCLE));
    cosArrayList.remove(positionToRemove);
    assertTrue("List size shall be 2", cosArrayList.size() == 1);
    assertTrue("COSArray size shall be 2", underlyingCOSArray.size() == 2);
    assertTrue("Backed COSArray size shall be 2", cosArrayList.toList().size() == 2);
    assertTrue("Removed annotation shall no longer appear in COSArrayList", cosArrayList.indexOf(toBeRemoved) == -1);
    assertTrue("Removed annotation shall no longer appear in underlying COSArray", underlyingCOSArray.indexOf(toBeRemoved.getCOSObject()) == -1);
    assertTrue("Removed annotation shall no longer appear in backed COSArray", cosArrayList.toList().indexOf(toBeRemoved.getCOSObject()) == -1);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) AnnotationFilter(com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter) Test(org.junit.Test)

Example 4 with AnnotationFilter

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter in project PdfBox-Android by TomRoush.

the class COSArrayListTest method removeFromFilteredListByObject.

@Test
public void removeFromFilteredListByObject() throws Exception {
    // retrieve all annotations from page but the link annotation
    // which is 2nd in list - see above setup
    AnnotationFilter annotsFilter = new AnnotationFilter() {

        @Override
        public boolean accept(PDAnnotation annotation) {
            return !(annotation instanceof PDAnnotationLink);
        }
    };
    COSArrayList<PDAnnotation> cosArrayList = (COSArrayList<PDAnnotation>) pdPage.getAnnotations(annotsFilter);
    COSArray underlyingCOSArray = pdPage.getCOSObject().getCOSArray(COSName.ANNOTS);
    assertTrue("Filtered COSArrayList size shall be 2", cosArrayList.size() == 2);
    assertTrue("Underlying COSArray shall have 3 entries", underlyingCOSArray.size() == 3);
    assertTrue("Backed COSArray shall have 3 entries", cosArrayList.toList().size() == 3);
    // remove aCircle annotation
    int positionToRemove = 1;
    PDAnnotation toBeRemoved = cosArrayList.get(positionToRemove);
    assertTrue("We should remove the circle annotation", toBeRemoved.getSubtype().equals(PDAnnotationSquareCircle.SUB_TYPE_CIRCLE));
    cosArrayList.remove(toBeRemoved);
    assertTrue("List size shall be 2", cosArrayList.size() == 1);
    assertTrue("COSArray size shall be 2", underlyingCOSArray.size() == 2);
    assertTrue("Backed COSArray size shall be 2", cosArrayList.toList().size() == 2);
    assertTrue("Removed annotation shall no longer appear in COSArrayList", cosArrayList.indexOf(toBeRemoved) == -1);
    assertTrue("Removed annotation shall no longer appear in underlying COSArray", underlyingCOSArray.indexOf(toBeRemoved.getCOSObject()) == -1);
    assertTrue("Removed annotation shall no longer appear in backed COSArray", cosArrayList.toList().indexOf(toBeRemoved.getCOSObject()) == -1);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) AnnotationFilter(com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter) Test(org.junit.Test)

Aggregations

AnnotationFilter (com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter)4 PDAnnotation (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation)4 Test (org.junit.Test)4 PDAnnotationLink (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink)3 COSArray (com.tom_roush.pdfbox.cos.COSArray)2 PDAnnotationSquareCircle (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle)1