Search in sources :

Example 1 with PDAnnotationLink

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

the class Splitter method processAnnotations.

private void processAnnotations(PDPage imported) throws IOException {
    List<PDAnnotation> annotations = imported.getAnnotations();
    for (PDAnnotation annotation : annotations) {
        if (annotation instanceof PDAnnotationLink) {
            PDAnnotationLink link = (PDAnnotationLink) annotation;
            PDDestination destination = link.getDestination();
            if (destination == null && link.getAction() != null) {
                PDAction action = link.getAction();
                if (action instanceof PDActionGoTo) {
                    destination = ((PDActionGoTo) action).getDestination();
                }
            }
            if (destination instanceof PDPageDestination) {
                // TODO preserve links to pages within the split result
                ((PDPageDestination) destination).setPage(null);
            }
        }
        // TODO preserve links to pages within the split result
        annotation.setPage(null);
    }
}
Also used : PDAction(com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination) PDDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDActionGoTo(com.tom_roush.pdfbox.pdmodel.interactive.action.PDActionGoTo)

Example 2 with PDAnnotationLink

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

the class TestPDPageAnnotationsFiltering method initMock.

@Before
public void initMock() {
    COSDictionary mockedPageWithAnnotations = new COSDictionary();
    COSArray annotsDictionary = new COSArray();
    annotsDictionary.add(new PDAnnotationRubberStamp().getCOSObject());
    annotsDictionary.add(new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE).getCOSObject());
    annotsDictionary.add(new PDAnnotationLink().getCOSObject());
    mockedPageWithAnnotations.setItem(COSName.ANNOTS, annotsDictionary);
    page = new PDPage(mockedPageWithAnnotations);
}
Also used : PDAnnotationRubberStamp(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Before(org.junit.Before)

Example 3 with PDAnnotationLink

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

the class COSArrayListTest method setUp.

/*
    * Create thre new different annotations an add them to the Java List/Array as
    * well as PDFBox List/Array implementations.
    */
@Before
public void setUp() throws Exception {
    annotationsList = new ArrayList<PDAnnotation>();
    PDAnnotationTextMarkup txtMark = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
    PDAnnotationLink txtLink = new PDAnnotationLink();
    PDAnnotationSquareCircle aCircle = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_CIRCLE);
    annotationsList.add(txtMark);
    annotationsList.add(txtLink);
    annotationsList.add(aCircle);
    assertTrue(annotationsList.size() == 3);
    tbcAnnotationsList = new ArrayList<PDAnnotation>();
    tbcAnnotationsList.add(txtMark);
    tbcAnnotationsList.add(txtLink);
    tbcAnnotationsList.add(aCircle);
    assertTrue(tbcAnnotationsList.size() == 3);
    annotationsArray = new COSArray();
    annotationsArray.add(txtMark);
    annotationsArray.add(txtLink);
    annotationsArray.add(aCircle);
    assertTrue(annotationsArray.size() == 3);
    tbcAnnotationsArray = new COSBase[3];
    tbcAnnotationsArray[0] = txtMark.getCOSObject();
    tbcAnnotationsArray[1] = txtLink.getCOSObject();
    tbcAnnotationsArray[2] = aCircle.getCOSObject();
    assertTrue(tbcAnnotationsArray.length == 3);
    // add the annotations to the page
    pdPage = new PDPage();
    pdPage.setAnnotations(annotationsList);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDAnnotationTextMarkup(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Before(org.junit.Before)

Example 4 with PDAnnotationLink

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink 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 5 with PDAnnotationLink

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink 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)

Aggregations

PDAnnotationLink (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink)8 COSArray (com.tom_roush.pdfbox.cos.COSArray)5 PDAnnotation (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation)5 AnnotationFilter (com.tom_roush.pdfbox.pdmodel.interactive.annotation.AnnotationFilter)3 PDAnnotationSquareCircle (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle)3 Test (org.junit.Test)3 Before (org.junit.Before)2 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)1 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)1 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)1 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)1 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)1 PDAction (com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction)1 PDActionGoTo (com.tom_roush.pdfbox.pdmodel.interactive.action.PDActionGoTo)1 PDAnnotationRubberStamp (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp)1 PDAnnotationTextMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup)1 PDBorderStyleDictionary (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)1 PDDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination)1