Search in sources :

Example 1 with PDAction

use of com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction 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 PDAction

use of com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction in project PdfBox-Android by TomRoush.

the class PDOutlineItem method findDestinationPage.

/**
 * This method will attempt to find the page in this PDF document that this outline points to.
 * If the outline does not point to anything then this method will return null. If the outline
 * is an action that is not a GoTo action then this method will also return null.
 *
 * @param doc The document to get the page from.
 *
 * @return The page that this outline will go to when activated or null if it does not point to
 * anything.
 * @throws IOException If there is an error when trying to find the page.
 */
public PDPage findDestinationPage(PDDocument doc) throws IOException {
    PDDestination dest = getDestination();
    if (dest == null) {
        PDAction outlineAction = getAction();
        if (outlineAction instanceof PDActionGoTo) {
            dest = ((PDActionGoTo) outlineAction).getDestination();
        }
    }
    if (dest == null) {
        return null;
    }
    PDPageDestination pageDestination = null;
    if (dest instanceof PDNamedDestination) {
        pageDestination = doc.getDocumentCatalog().findNamedDestinationPage((PDNamedDestination) dest);
        if (pageDestination == null) {
            return null;
        }
    } else if (dest instanceof PDPageDestination) {
        pageDestination = (PDPageDestination) dest;
    } else {
        throw new IOException("Error: Unknown destination type " + dest);
    }
    PDPage page = pageDestination.getPage();
    if (page == null) {
        // Malformed PDF: local destinations must have a page object,
        // not a page number, these are meant for remote destinations.
        int pageNumber = pageDestination.getPageNumber();
        if (pageNumber != -1) {
            page = doc.getPage(pageNumber);
        }
    }
    return page;
}
Also used : PDAction(com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction) PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDNamedDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination) PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination) PDDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination) IOException(java.io.IOException) PDActionGoTo(com.tom_roush.pdfbox.pdmodel.interactive.action.PDActionGoTo)

Aggregations

PDAction (com.tom_roush.pdfbox.pdmodel.interactive.action.PDAction)2 PDActionGoTo (com.tom_roush.pdfbox.pdmodel.interactive.action.PDActionGoTo)2 PDDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination)2 PDPageDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination)2 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)1 PDAnnotation (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation)1 PDAnnotationLink (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink)1 PDNamedDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination)1 IOException (java.io.IOException)1